Question

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++.

Was it helpful?

Solution

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).

OTHER TIPS

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 ∞/∞.

Refernce Link1

Refernce Link2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top