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