问题
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++.
回答1:
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).
回答2:
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
来源:https://stackoverflow.com/questions/15288406/what-is-the-difference-between-ind-and-nan-numbers