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("");