Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ sqrt returns -1.#IND000000000000

Tags:

c++

sqrt

In specific:

Im doing some math operations, and the application keeps crashing because a double that is widely used happens to get the value: -1.#IND000000000000 when "some" numbers are sqrt'ed... What is this? Indefinite? Infinite? Too big to fit? Not a perfect Square Root? Is there any way to solve this? Thanks in advance! EDIT: How can i check if a double has this value ? I tried: if (x == 0x-1.#IND000000000000) and other variations but did not work. Is it possible to check to see if a variable has this value ?

like image 672
Ælex Avatar asked Jan 14 '11 06:01

Ælex


1 Answers

Actually, the string -1.#IND000000000000 is not a value, returned by a function, but it is one of a common representations of a QNaN, Quiet Not-a-Number, the special IEEE-754 value representing the invalid number, that won't cause the exception (there are also SNaN, Signalling NaN, which would cause the floating point exception, if enabled). The common cause of this is calling a function with argument out of it's domain.

like image 111
mbaitoff Avatar answered Oct 11 '22 21:10

mbaitoff