Namespaces
Variants

fpclassify

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(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
fpclassify
(C99)
(C99)
(C99)
(C99)
(C23)
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>
#define fpclassify(arg) /* implementation defined */
(C99부터)

부동 소수점 값 arg 을 다음 범주로 분류합니다: zero, subnormal, normal, infinite, NAN, 또는 구현 정의 범주. 매크로는 정수 값을 반환합니다.

FLT_EVAL_METHOD 는 무시됩니다: 인수가 해당 타입보다 더 넓은 범위와 정밀도로 평가되더라도, 먼저 해당 의미론적 타입으로 변환되며 분류는 이를 기반으로 이루어집니다: 일반적인 long double 값이 double로 변환될 때 서브노멀이 되거나 float 로 변환될 때 0이 될 수 있습니다.

목차

매개변수

arg - 부동소수점 값

반환값

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

예제

#include <float.h>
#include <math.h>
#include <stdio.h>
const char* show_classification(double x)
{
    switch(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(void)
{
    printf("1.0/0.0 is %s\n", show_classification(1 / 0.0));
    printf("0.0/0.0 is %s\n", show_classification(0.0 / 0.0));
    printf("DBL_MIN/2 is %s\n", show_classification(DBL_MIN / 2));
    printf("-0.0 is %s\n", show_classification(-0.0));
    printf("1.0 is %s\n", show_classification(1.0));
}

출력:

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

참고문헌

  • C23 표준 (ISO/IEC 9899:2024):
  • 7.12.3.1 fpclassify 매크로 (p: TBD)
  • C17 표준 (ISO/IEC 9899:2018):
  • 7.12.3.1 fpclassify 매크로 (p: TBD)
  • C11 표준 (ISO/IEC 9899:2011):
  • 7.12.3.1 fpclassify 매크로 (p: 235)
  • C99 표준 (ISO/IEC 9899:1999):
  • 7.12.3.1 fpclassify 매크로 (p: 216)

참고 항목

주어진 숫자가 유한한 값인지 검사합니다
(함수 매크로)
(C99)
주어진 숫자가 무한대인지 검사합니다
(함수 매크로)
(C99)
주어진 숫자가 NaN인지 검사합니다
(함수 매크로)
주어진 숫자가 정규(normal) 수인지 검사합니다
(함수 매크로)
C++ documentation for fpclassify