Defined in header <math.h> | ||
---|---|---|
float nanf( const char* arg ); | (since C99) | |
double nan( const char* arg ); | (since C99) | |
long double nanl( const char* arg ); | (since C99) |
Converts the implementation-defined character string arg
into the corresponding quiet NaN value, as if by calling strtod
, strtof
, or strtold
, respectively, as follows:
The call nan("string")
is equivalent to the call strtod("NAN(string)", (char**)NULL);
.
The call nan("")
is equivalent to the call strtod("NAN()", (char**)NULL);
.
The call nan(NULL)
is equivalent to the call strtod("NAN", (char**)NULL);
.
Parameters
arg | - | narrow character string identifying the contents of a NaN |
Return value
The quiet NaN value that corresponds to the identifying string arg
or zero if the implementation does not support quiet NaNs.
Example
#include <stdio.h> #include <math.h> #include <stdint.h> #include <inttypes.h> #include <string.h> int main(void) { double f1 = nan("1"); uint64_t f1n; memcpy(&f1n, &f1, sizeof f1); printf("nan(\"1\") = %f (%" PRIx64 ")\n", f1, f1n); double f2 = nan("2"); uint64_t f2n; memcpy(&f2n, &f2, sizeof f2); printf("nan(\"2\") = %f (%" PRIx64 ")\n", f2, f2n); }
Possible output:
nan("1") = nan (7ff8000000000001) nan("2") = nan (7ff8000000000002)
References
- C11 standard (ISO/IEC 9899:2011):
- 7.12.11.2 The nan functions (p: 256)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- F.10.8.2 The nan functions (p: 529)
- C99 standard (ISO/IEC 9899:1999):
- 7.12.11.2 The nan functions (p: 237)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- F.9.8.2 The nan functions (p: 465)
See also
(C99) | checks if the given number is NaN (function) |
(C99) | evaluates to a quiet NaN of type float (macro constant) |
C++ documentation for nanf, nan, nanl |
Please login to continue.