I was surprised by the number of C++ facilities to represent quiet NaN value. I found three standard ways:
std::numeric_limits<T>::quiet_NaN()
- generic, and I thought it was the chosen onestd::nan
, std::nanf
, std::nanl
- family of functions accepting const char*
argumentNAN
- a macro, "which evaluates to a quiet not-a-number"Each of these were introduced in C++11. I have several questions regarding this:
const char*
argument stand for in std::nan
and co? How it is used?std::nan
, std::nanl
and std::nanf
are inherited from the C Math library; so is the NAN macro. They all live in C's <math.h>
. As @NicolBolas suggests, however, they were only introduced in C++11 because they were not part of ANSI C, but rather of C99, a newer version of the C language standard. The C++ standards committee was making an effort to 'update' the C compatibility, so to speak.
std::numeric_limits<T>
was designed for C++ itself (well before C++11), and that's what I'd use.
So, the bottom line answer is: C99 compatibility.