Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      nan, nanf, nanl, nand32, nand64, nand128

      From cppreference.com
      <c‎ |numeric‎ |math
       
       
       
      Common mathematical functions
      Functions
      Basic operations
      (C99)
      (C99)
      (C99)
      nannanfnanlnandN
      (C99)(C99)(C99)(C23)
      Maximum/minimum operations
      (C99)
      (C99)
      Exponential functions
      (C23)
      (C99)
      (C99)
      (C23)
      (C23)

      (C99)
      (C99)(C23)
      (C23)
      (C23)
      Power functions
      (C99)
      (C23)
      (C23)

      (C99)
      (C23)
      (C23)
      Trigonometric and hyperbolic functions
      (C23)
      (C23)
      (C23)
      (C23)
      (C99)
      (C99)
      (C99)
      Nearest integer floating-point
      (C99)(C99)(C99)
      (C23)(C23)(C23)(C23)
      Floating-point manipulation
      (C99)(C99)
      (C99)(C23)
      (C99)
      Narrowing operations
      (C23)
      (C23)
      (C23)
      (C23)
      (C23)
      (C23)
      Quantum and quantum exponent
      Decimal re-encoding functions
      Total order and payload functions
      Classification
      Error and gamma functions
      (C99)
      (C99)
      (C99)
      (C99)
      Types
      Macro constants
      Special floating-point values
      (C99)(C23)
      Arguments and return values
      Error handling
      Fast operation indicators
       
      Defined in header<math.h>
      float       nanf(constchar* arg);
      (1)(since C99)
      double      nan(constchar* arg);
      (2)(since C99)
      longdouble nanl(constchar* arg);
      (3)(since C99)
      _Decimal32  nand32(constchar* arg);
      (4)(since C23)
      _Decimal64  nand64(constchar* arg);
      (5)(since C23)
      _Decimal128 nand128(constchar* arg);
      (6)(since C23)

      Converts the implementation-defined character stringarg into the corresponding quiet NaN value, as if by calling the appropriate parsing functionstrtoX, as follows:

      • The callnan("n-char-sequence"), wheren-char-sequence is a sequence of digits, Latin letters, and underscores, is equivalent to the call/*strtoX*/("NAN(n-char-sequence)",(char**)NULL);.
      • The callnan("") is equivalent to the call/*strtoX*/("NAN()",(char**)NULL);.
      • The callnan("string"), wherestring is neither ann-char-sequence nor an empty string, is equivalent to the call/*strtoX*/("NAN",(char**)NULL);.
      1) The parsing function isstrtof.
      2) The parsing function isstrtod.
      3) The parsing function isstrtold.
      4) The parsing function isstrtod32.
      5) The parsing function isstrtod64.
      6) The parsing function isstrtod128.

      The functions returning decimal floating point values are declared if and only the implementation predefines__STDC_IEC_60559_DFP__ (i.e. the implementation supports decimal floating point numbers).

      (since C23)

      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 <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); double f3= nan("0xF");uint64_t f3n;memcpy(&f3n,&f3,sizeof f3);printf("nan(\"0xF\") = %f (%"PRIx64")\n", f3, f3n);}

      Possible output:

      nan("1")   = nan (7ff8000000000001)nan("2")   = nan (7ff8000000000002)nan("0xF") = nan (7ff800000000000f)

      [edit]References

      • C17 standard (ISO/IEC 9899:2018):
      • 7.12.11.2 The nan functions (p: 186-187)
      • F.10.8.2 The nan functions (p: 386)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.12.11.2 The nan functions (p: 256)
      • F.10.8.2 The nan functions (p: 529)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.12.11.2 The nan functions (p: 237)
      • F.9.8.2 The fabs functions (p: 465)

      [edit]See also

      (C99)
      checks if the given number is NaN
      (function macro)[edit]
      (C99)
      evaluates to a quiet NaN of typefloat
      (macro constant)[edit]
      C++ documentation fornanf,nan,nanl
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/math/nan&oldid=133964"

      [8]ページ先頭

      ©2009-2025 Movatter.jp