C ++ sqrt returns -1. # IND000000000000

In particular:

Im doing some math operations, and the application continues to crash because a double, which is widely used, gets a value of -1. # IND000000000000 when "some" sqrt'ed numbers ... What is it? Vague? Endless? 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 value has this value? I tried: if (x == 0x-1. # IND000000000000) and other options, but didn't work. Is it possible to check if a variable has this value?

+6
c ++ sqrt
source share
6 answers

Actually, the string -1.#IND000000000000 not the value returned by the function, but it is one of the general representations of QNaN , Quiet Not-a-Number , a special value of IEEE-754 representing an invalid number that will not throw an exception (there is also SNaN , Signalling NaN ), which will throw a floating point exception if enabled). A common reason for this is a function call with an argument from this domain.

+10
source share

NaNs (for example, the "undefined" that you have and the "infinity") can be detected by checking x == x (it is not true for NaN and true for any finite number).

+5
source share

The value #IND000000000000 is an invalid numeric value. This is often called the QNaN (Quiet Not-A-Number) value, because it is an undefined type, but does not lead to a malfunction.

Most likely, the elusive numbers whose square root you are trying to determine are negative numbers for which this value is not defined. See Wikipedia for more details.

The solution will first require you to determine where the problem is. This means that you need to either go through it using the debugger, or look at the values ​​of the variables, or place your code so that we can do the same.

+2
source share

If the argument is negative, a domain error occurs by setting the global variable errno to EDOM.

+1
source share

Without the use of a complex type, the sqrt value of any value below 0 should throw an exception.

0
source share

This is NaN (not a number). This means that you called sqrt with a negative argument.

Cheers and hth.,

0
source share

All Articles