Namespaces
Variants

std::numeric_limits<T>:: signaling_NaN

From cppreference.net
Utilities library
static T signaling_NaN ( ) throw ( ) ;
(C++11 이전)
static constexpr T signaling_NaN ( ) noexcept ;
(C++11 이후)

부동 소수점 타입 T 로 표현되는 특수 값 "신호 발생 NaN(Not-a-Number) "을 반환합니다. std:: numeric_limits < T > :: has_signaling_NaN == true 인 경우에만 의미가 있습니다. IEEE 754(부동 소수점 숫자의 가장 일반적인 이진 표현)에서 지수 비트가 모두 설정되고 가수 비트가 적어도 하나 설정된 모든 값은 NaN을 나타냅니다. 가수의 어떤 값이 정적 NaN 또는 신호 발생 NaN을 나타내는지, 그리고 부호 비트가 의미 있는지 여부는 구현에 따라 정의됩니다.

목차

반환값

T std:: numeric_limits < T > :: signaling_NaN ( )
/* 비전문화 */ T ( )
bool false
char 0
signed char 0
unsigned char 0
wchar_t 0
char8_t (C++20 이후) 0
char16_t (C++11 이후) 0
char32_t (C++11 이후) 0
short 0
unsigned short 0
int 0
unsigned int 0
long 0
unsigned long 0
long long (C++11 이후) 0
unsigned long long (C++11 이후) 0
float 구현 정의 ( FLT_SNAN 일 수 있음)
double 구현 정의 ( DBL_SNAN 일 수 있음)
long double 구현 정의 ( LDBL_SNAN 일 수 있음)

참고 사항

NaN은 절대로 자기 자신과 같다고 비교되지 않습니다. IEEE-754에 따르면 NaN을 복사할 때 비트 표현(부호와 payload )을 보존할 필요는 없지만, 대부분의 구현체에서는 보존합니다.

시그널링 NaN이 산술 표현식의 인수로 사용될 때, 적절한 부동 소수점 예외가 발생할 수 있으며 NaN은 "정숙화(quieted)"됩니다. 즉, 표현식은 정숙 NaN을 반환합니다.

예제

신호 NaN을 사용하여 부동 소수점 예외를 발생시키는 방법을 보여줍니다:

#include <cfenv>
#include <iostream>
#include <limits>
#pragma STDC_FENV_ACCESS on
void show_fe_exceptions()
{
    int n = std::fetestexcept(FE_ALL_EXCEPT);
    if (n & FE_INVALID)
        std::cout << "FE_INVALID is raised\n";
    else if (n == 0)
        std::cout << "no exceptions are raised\n";
    std::feclearexcept(FE_ALL_EXCEPT);
}
int main()
{
    double snan = std::numeric_limits<double>::signaling_NaN();
    std::cout << "After sNaN was obtained, ";
    show_fe_exceptions();
    double qnan = snan * 2.0;
    std::cout << "After sNaN was multiplied by 2, ";
    show_fe_exceptions();
    double qnan2 = qnan * 2.0;
    std::cout << "After the quieted NaN was multiplied by 2, ";
    show_fe_exceptions();
    std::cout << "The result is " << qnan2 << '\n';
}

출력:

After sNaN was obtained, no exceptions are raised
After sNaN was multiplied by 2, FE_INVALID is raised
After the quieted NaN was multiplied by 2, no exceptions are raised
The result is nan

참고 항목

부동 소수점 타입이 특수 값 "신호 NaN(signaling not-a-number)"을 표현할 수 있는지 식별합니다
(public static member constant)
[static]
주어진 부동 소수점 타입의 quiet NaN 값을 반환합니다
(public static member function)
(C++11)
주어진 숫자가 NaN인지 확인합니다
(function)