std::nan,st...f,std::nanl(3)
π NAME π
okay so this is the C++ Standard Library manual page β header literally says C++ Standard Libary, no cap β for std::nan, std::nanf, and std::nanl, a.k.a. std::nan,st...f,std::nanl(3) π
std::nan, std::nanf, std::nanl β yes bestie, the name line is that trio, and the description line is the exact same trio again: std::nan,std::nanf,std::nanl. Iconic repetition, honestly π
β¨ Synopsis β¨
Defined in header <cmath>:
float nanf( const char* arg ); (1) (since C++11)
double nan ( const char* arg ); (2) (since C++11)
long double nanl( const char* arg ); (3) (since C++11)
so whatβs the tea? These convert the character string arg into the corresponding quiet NaN value, as if by calling std::strtof, std::strtod, or std::strtold, respectively. Lowkey magical β¨
- The call
std::nanf("n-char-sequence"), wheren-char-sequenceis a sequence of digits, ASCII letters, and underscores, is equivalent to the callstd::strtof("NAN(n-char-sequence)", (char**)nullptr);. The callstd::nanf("")is equivalent to the callstd::strtof("NAN()", (char**)nullptr);. The callstd::nanf("string"), wherestringis neither ann-char-sequencenor an empty string, is equivalent to the callstd::strtof("NAN", (char**)nullptr);. - Same as (1), but calls
std::strtodinstead ofstd::strtof. - Same as (1), but calls
std::strtoldinstead ofstd::strtof.
πΈ Parameters πΈ
argβ narrow character string identifying the contents of a NaN. Thatβs it, bestie π«Ά
π Return value π
The quiet NaN value that corresponds to the identifying string arg β or zero if the implementation does not support quiet NaNs. π
If the implementation supports IEEE floating-point arithmetic (IEC 60559), it also supports quiet NaNs. Slay π
π¦ Error handling π¦
This function is not subject to any of the error conditions specified in math_errhandling. So no extra error-handling drama here, bestie. Periodt π
π Example π
// Run this code
#include <cmath>
#include <cstdint>
#include <cstring>
#include <iostream>
int main()
{
double f1 = std::nan("1");
std::uint64_t f1n; std::memcpy(&f1n, &f1, sizeof f1);
std::cout << "nan(\"1\") = " << f1 << " (" << std::hex << f1n << ")\n";
double f2 = std::nan("2");
std::uint64_t f2n; std::memcpy(&f2n, &f2, sizeof f2);
std::cout << "nan(\"2\") = " << f2 << " (" << std::hex << f2n << ")\n";
}
π« Possible output π«
nan("1") = nan (7ff0000000000001)
nan("2") = nan (7ff0000000000002)
π See also π
isnanβ checks if the given number is NaN (C++11) (function)NANβ evaluates to a quiet NaN of typefloat(C++11) (macro constant)has_quiet_NaNβ identifies floating-point types that can represent the special value "quiet not-a-number" (NaN) [static] (public static member constant ofstd::numeric_limits<T>)has_signaling_NaNβ identifies floating-point types that can represent the special value "signaling not-a-number" (NaN) [static] (public static member constant ofstd::numeric_limits<T>)quiet_NaNβ returns a quiet NaN value of the given floating-point type [static] (public static member function ofstd::numeric_limits<T>)signaling_NaNβ returns a signaling NaN value of the given floating-point type [static] (public static member function ofstd::numeric_limits<T>)- C documentation for
nanf,nan,nanl
okay thatβs the whole page, bestie π«Ά source/version/date tea: http://cppreference.com, 2024.06.10, std::nan,st...f,std::nanl(3). Mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms