A NAN value means Not A Number and IND value means Indeterminate number. But what is the difference between these two. How can we represent both in c++.
2 Answers
But what is the difference between these two.
They are both the same thing. Some platforms choose to display a non-number as some variant of NaN
, while others choose to display it as some variant of IND
.
How can we represent both in c++.
std::numeric_limits<double>::quiet_NaN()
(or float
or long double
, if you prefer).

- 249,747
- 28
- 448
- 644
-
1Apparently, they are not the same, per-se. On Microsoft platform, IND appears to be a special case for NaN. Specifically, for IND, the exponent is 0xFF, and the mantissa is 0x400000. Any other nonzero mantissa gives a NaN. – ysap May 13 '17 at 14:48
If your operation would generate a larger positive number than could be stored in a double, the operation will return 1.#INF
on Windows or inf on Linux
Some operations don't make mathematical sense, such as taking the square root of a negative number.Both sqrt(-1.0)
and log(-1.0)
would return a NaN, the generic term for a "number" that is "not a number".
Windows displays a NaN as -1.#IND
("IND" for "indeterminate") while Linux displays nan
. Other operations that would return a NaN
include 0/0, 0*∞, and ∞/∞.

- 1
- 1
-
1It's not Windows vs Linux, it's the compiler's standard library that dictates how NaN should be shown. – Alexey Frunze Mar 08 '13 at 07:30
-
"Some operations don't make mathematical sense" The operations do make mathematical sense, but the results can't be stored in a floating point number, i.e. sqrt(-1.0) is i, an imaginary number that can't be stored in a float – 1stCLord May 17 '17 at 13:08
-
-