Precision issues in sqrt() function of C++

Revision en2, by nik1996, 2019-01-15 18:10:43

Hi all,

Recently I was solving problem Sad Powers. In the editorial of the problem it is mentioned that sqrt() function of c++ has some precision issues. On using the function in my problem on some value gives me wrong answer. After looking others solution I observed that some have used additional checks. e.g. If square root of value x is required then many solutions have checked for both x and (x-1) /(x+1). I could not understand why that additional check is required.

Can anybody please tell why this additional check is required or what are the issues with sqrt() function?

Thanks!!

Tags c++, c++ 11, c++ 14, sqrt

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English nik1996 2019-01-15 18:10:43 7 (published)
en1 English nik1996 2019-01-15 18:09:09 685 Initial revision (saved to drafts)