Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::nan,std::nanf,std::nanl

      From cppreference.com
      <cpp‎ |numeric‎ |math
       
       
       
      Common mathematical functions
      Nearest integer floating point operations
      (C++11)(C++11)(C++11)
      (C++11)
      (C++11)
      (C++11)(C++11)(C++11)
      Floating point manipulation functions
      (C++11)(C++11)
      (C++11)
      (C++11)
      Classification and comparison
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      Types
      (C++11)
      (C++11)
      (C++11)
      Macro constants
       
      Defined in header<cmath>
      float       nanf(constchar* arg);
      (1)(since C++11)
      double      nan(constchar* arg);
      (2)(since C++11)
      longdouble nanl(constchar* arg);
      (3)(since C++11)

      Converts the character stringarg into the corresponding quiet NaN value, as if by callingstd::strtof,std::strtod, orstd::strtold, respectively.

      1) The callstd::nanf("n-char-sequence"), wheren-char-sequence is 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"), wherestring is neither ann-char-sequence nor an empty string, is equivalent to the callstd::strtof("NAN",(char**)nullptr);.
      2) Same as(1), but callsstd::strtod instead ofstd::strtof.
      3) Same as(1), but callsstd::strtold instead ofstd::strtof.

      Contents

      [edit]Parameters

      arg - narrow character string identifying the contents of a NaN

      [edit]Return value

      The quiet NaN value that corresponds to the identifying stringarg 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.

      [edit]Error handling

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

      [edit]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)

      [edit]See also

      (C++11)
      checks if the given number is NaN
      (function)[edit]
      (C++11)
      evaluates to a quiet NaN of typefloat
      (macro constant)[edit]
      identifies floating-point types that can represent the special value "quiet not-a-number" (NaN)
      (public static member constant ofstd::numeric_limits<T>)[edit]
      identifies floating-point types that can represent the special value "signaling not-a-number" (NaN)
      (public static member constant ofstd::numeric_limits<T>)[edit]
      [static]
      returns a quiet NaN value of the given floating-point type
      (public static member function ofstd::numeric_limits<T>)[edit]
      returns a signaling NaN value of the given floating-point type
      (public static member function ofstd::numeric_limits<T>)[edit]
      C documentation fornanf,nan,nanl
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/math/nan&oldid=149109"

      [8]ページ先頭

      ©2009-2025 Movatter.jp