Namespaces
Variants

nan, nanf, nanl, nand32, nand64, nand128

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
nan nanf nanl nand N
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
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
Arguments and return values
Error handling
Fast operation indicators
헤더 파일에 정의됨 <math.h>
float nanf ( const char * arg ) ;
(1) (C99부터)
double nan ( const char * arg ) ;
(2) (C99부터)
long double nanl ( const char * arg ) ;
(3) (C99부터)
_Decimal32  nand32 ( const char * arg ) ;
(4) (C23부터)
_Decimal64  nand64 ( const char * arg ) ;
(5) (C23부터)
_Decimal128 nand128 ( const char * arg ) ;
(6) (C23부터)

구현에서 정의된 문자 문자열 arg 를 해당 quiet NaN 값으로 변환합니다. 마치 다음과 같은 적절한 파싱 함수 strtoX 를 호출하는 것처럼:

  • nan ( "n-char-sequence" ) 호출은 n-char-sequence 가 숫자, 라틴 문자, 밑줄로 구성된 시퀀스일 때 /*strtoX*/ ( "NAN(n-char-sequence)" , ( char ** ) NULL ) ; 호출과 동등합니다.
  • nan ( "" ) 호출은 /*strtoX*/ ( "NAN()" , ( char ** ) NULL ) ; 호출과 동등합니다.
  • nan ( "string" ) 호출은 string n-char-sequence 도 아니고 빈 문자열도 아닐 때 /*strtoX*/ ( "NAN" , ( char ** ) NULL ) ; 호출과 동등합니다.
1) 파싱 함수는 strtof 입니다.
2) 파싱 함수는 strtod 입니다.
3) 파싱 함수는 strtold 입니다.
4) 파싱 함수는 strtod32 입니다.
5) 파싱 함수는 strtod64 입니다.
6) 파싱 함수는 strtod128 입니다.

십진 부동 소수점 값을 반환하는 함수들은 구현체가 __STDC_IEC_60559_DFP__ 를 미리 정의하는 경우에만 선언됩니다 (즉, 구현체가 십진 부동 소수점 숫자를 지원하는 경우).

(C23부터)

목차

매개변수

arg - NaN의 내용을 식별하는 좁은 문자 문자열

반환값

식별 문자열 arg 에 해당하는 정적 NaN(Quiet NaN) 값 또는 구현체가 정적 NaN을 지원하지 않는 경우 0입니다.

구현이 IEEE 부동 소수점 연산(IEC 60559)을 지원하는 경우, 조용한 NaN도 지원합니다.

오류 처리

이 함수는 math_errhandling 에 명시된 어떠한 오류 조건에도 적용되지 않습니다.

예제

#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);
}

가능한 출력:

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

참고문헌

  • C17 표준 (ISO/IEC 9899:2018):
  • 7.12.11.2 nan 함수들 (p: 186-187)
  • F.10.8.2 nan 함수들 (p: 386)
  • C11 표준 (ISO/IEC 9899:2011):
  • 7.12.11.2 nan 함수 (p: 256)
  • F.10.8.2 nan 함수 (p: 529)
  • C99 표준 (ISO/IEC 9899:1999):
  • 7.12.11.2 nan 함수 (p: 237)
  • F.9.8.2 fabs 함수 (p: 465)

참고 항목

(C99)
주어진 숫자가 NaN인지 확인합니다
(함수 매크로)
(C99)
float 타입의 quiet NaN으로 평가됩니다
(매크로 상수)
C++ documentation for nanf , nan , nanl