How to return NaN in C++
Since C++11 returning NaN
as double
is as simple as
return_nan_double.cpp
#include <cmath>
return std::nan("");
In case you want to return a float
use
return_nan_float.cpp
#include <cmath>
return std::nanf("");
In the rare case of a long double
use
return_nan_longdouble.cpp
#include <cmath>
return std::nan("");
Check out similar posts by category:
C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow