std::nan, std::nanf, std::nanl - cppreference.com

From cppreference.com

Defined in header

<cmath>

floatnanf(constchar*arg); (1) (since C++11)doublenan(constchar*arg); (2) (since C++11)longdoublenanl(constchar*arg); (3) (since C++11)Converts the character string arg into the corresponding quiet NaN value, as if by calling

std::strtof

,

std::strtod

, or

std::strtold

, respectively.

1) The call std::nanf("n-char-sequence"), where n-char-sequence is a sequence of digits, ASCII letters, and underscores, is equivalent to the call std::strtof("NAN(n-char-sequence)",(char**)nullptr);.

The call std::nanf("") is equivalent to the call std::strtof("NAN()",(char**)nullptr);.

The call std::nanf("string"), where string is neither an n-char-sequence nor an empty string, is equivalent to the call std::strtof("NAN",(char**)nullptr);.

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.

If the implementation supports IEEE floating-point arithmetic (IEC 60559), it also supports quiet NaNs.

Error handling

This function is not subject to any of the error conditions specified in

math_errhandling

.

Example

Run this code

#include<cmath>#include<cstdint>#include<cstring>#include<iostream>intmain(){doublef1=std::nan("1");std::uint64_tf1n;std::memcpy(&f1n,&f1,sizeoff1);std::cout<<"nan(\"1\") = "<<f1<<" ("<<std::hex<<f1n<<")\n";doublef2=std::nan("2");std::uint64_tf2n;std::memcpy(&f2n,&f2,sizeoff2);std::cout<<"nan(\"2\") = "<<f2<<" ("<<std::hex<<f2n<<")\n";}Possible output:

nan("1") = nan (7ff0000000000001) nan("2") = nan (7ff0000000000002) See also

isnan

(C++11)

checks if the given number is NaN
(function)

[edit]

NAN

(C++11)

evaluates to a quiet NaN of type float (if exists)
(macro constant)

[edit]

has_quiet_NaN

[static]

identifies floating-point types that can represent the special value “quiet not-a-number” (NaN)
(public static member constant of std::numeric_limits<T>)

[edit]

has_signaling_NaN

[static]

identifies floating-point types that can represent the special value “signaling not-a-number” (NaN)
(public static member constant of std::numeric_limits<T>)

[edit]

quiet_NaN

[static]

returns a quiet NaN value of the given floating-point type
(public static member function of std::numeric_limits<T>)

[edit]

signaling_NaN

[static]

returns a signaling NaN value of the given floating-point type
(public static member function of std::numeric_limits<T>)

[edit]

C documentation

for nanf, nan, nanl