Namespaces
Variants

std:: fpclassify

From cppreference.net
Common mathematical functions
Nearest integer floating point operations
(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
fpclassify
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Types
(C++11)
(C++11)
(C++11)
Macro constants
헤더 파일에 정의됨 <cmath>
(1)
int fpclassify ( float num ) ;

int fpclassify ( double num ) ;

int fpclassify ( long double num ) ;
(C++11부터)
(C++23까지)
constexpr int fpclassify ( /* floating-point-type */ num ) ;
(C++23부터)
헤더 파일에 정의됨 <cmath>
template < class Integer >
int fpclassify ( Integer num ) ;
(A) (C++11부터)
(C++23부터 constexpr)
1) 부동 소수점 값 num 을 다음 범주로 분류합니다: 영(zero), 서브노멀(subnormal), 노멀(normal), 무한대(infinite), NAN, 또는 구현 정의 범주. 라이브러리는 std::fpclassify 의 오버로드를 매개변수 num 의 타입으로서 모든 cv-한정자가 없는 부동 소수점 타입에 대해 제공합니다. (C++23부터)
A) 모든 정수 타입에 대해 추가적인 오버로드가 제공되며, 이들은 double 로 처리됩니다.

목차

매개변수

num - 부동 소수점 또는 정수 값

반환값

다음 중 하나: FP_INFINITE , FP_NAN , FP_NORMAL , FP_SUBNORMAL , FP_ZERO 또는 구현에서 정의된 타입으로, num 의 범주를 지정합니다.

참고 사항

추가 오버로드는 반드시 (A) 와 정확히 동일하게 제공될 필요는 없습니다. 정수 타입의 인수 num 에 대해 std :: fpclassify ( num ) std :: fpclassify ( static_cast < double > ( num ) ) 와 동일한 효과를 가지도록 보장하기에 충분하기만 하면 됩니다.

예제

#include <cfloat>
#include <cmath>
#include <iostream>
auto show_classification(double x)
{
    switch (std::fpclassify(x))
    {
        case FP_INFINITE:
            return "Inf";
        case FP_NAN:
            return "NaN";
        case FP_NORMAL:
            return "normal";
        case FP_SUBNORMAL:
            return "subnormal";
        case FP_ZERO:
            return "zero";
        default:
            return "unknown";
    }
}
int main()
{
    std::cout << "1.0/0.0 is " << show_classification(1 / 0.0) << '\n'
              << "0.0/0.0 is " << show_classification(0.0 / 0.0) << '\n'
              << "DBL_MIN/2 is " << show_classification(DBL_MIN / 2) << '\n'
              << "-0.0 is " << show_classification(-0.0) << '\n'
              << "1.0 is " << show_classification(1.0) << '\n';
}

출력:

1.0/0.0 is Inf
0.0/0.0 is NaN
DBL_MIN/2 is subnormal
-0.0 is zero
1.0 is normal

참고 항목

(C++11)
주어진 숫자가 유한한 값을 가지는지 검사합니다
(함수)
(C++11)
주어진 숫자가 무한한지 검사합니다
(함수)
(C++11)
주어진 숫자가 NaN인지 검사합니다
(함수)
(C++11)
주어진 숫자가 정규화된 숫자인지 검사합니다
(함수)
모든 기본 숫자 타입의 속성을 조회하기 위한 인터페이스를 제공합니다
(클래스 템플릿)
C 문서 for fpclassify