Namespaces
Variants

fdim, fdimf, fdiml

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
fdim
(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
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 fdimf ( float x, float y ) ;
(1) (C99부터)
double fdim ( double x, double y ) ;
(2) (C99부터)
long double fdiml ( long double x, long double y ) ;
(3) (C99부터)
헤더 파일에 정의됨 <tgmath.h>
#define fdim( x, y )
(4) (C99부터)
1-3) x y 사이의 양의 차이를 반환합니다. 즉, x > y 인 경우 x - y 를 반환하고, 그렇지 않은 경우( x≤y ) +0을 반환합니다.
4) 타입-제네릭 매크로: 인자 중 하나라도 long double 타입을 가지면 fdiml 이 호출됩니다. 그렇지 않고 인자 중 하나라도 정수 타입이나 double 타입을 가지면 fdim 이 호출됩니다. 그 외의 경우에는 fdimf 이 호출됩니다.

목차

매개변수

x, y - 부동소수점 값

반환값

성공 시, x y 사이의 양의 차이를 반환합니다.

오버플로로 인한 범위 오류가 발생하는 경우, +HUGE_VAL , +HUGE_VALF , 또는 +HUGE_VALL 가 반환됩니다.

언더플로로 인한 범위 오류가 발생하면, 올바른 값(반올림 후)이 반환됩니다.

오류 처리

오류는 Template:rllpt 에 명시된 대로 보고됩니다.

구현이 IEEE 부동 소수점 연산(IEC 60559)을 지원하는 경우,

  • 인수 중 하나라도 NaN이면 NaN이 반환됩니다.

참고 사항

NaN 처리 요구 사항을 제외하고는 fmax ( x - y, 0 ) 와 동등합니다.

예제

#include <errno.h>
#include <fenv.h>
#include <math.h>
#include <stdio.h>
// #pragma STDC FENV_ACCESS ON
int main(void)
{
    printf("fdim(4, 1) = %f, fdim(1, 4)=%f\n", fdim(4,1), fdim(1,4));
    printf("fdim(4,-1) = %f, fdim(1,-4)=%f\n", fdim(4,-1), fdim(1,-4));
    //error handling
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("fdim(1e308, -1e308) = %f\n", fdim(1e308, -1e308));
    if (errno == ERANGE)
        perror("    errno == ERANGE");
    if (fetestexcept(FE_OVERFLOW))
        puts("    FE_OVERFLOW raised");
}

가능한 출력:

fdim(4, 1) = 3.000000, fdim(1, 4)=0.000000
fdim(4,-1) = 5.000000, fdim(1,-4)=5.000000
fdim(1e308, -1e308) = inf
    errno == ERANGE: Numerical result out of range
    FE_OVERFLOW raised

참고문헌

  • C23 표준 (ISO/IEC 9899:2024):
  • 7.12.12.1 fdim 함수들 (p: TBD)
  • 7.25 타입-제네릭 수학 <tgmath.h> (p: TBD)
  • F.10.9.1 fdim 함수들 (p: TBD)
  • C17 표준 (ISO/IEC 9899:2018):
  • 7.12.12.1 fdim 함수들 (p: 187-188)
  • 7.25 타입-제네릭 수학 <tgmath.h> (p: 272-273)
  • F.10.9.1 fdim 함수들 (p: 386)
  • C11 표준 (ISO/IEC 9899:2011):
  • 7.12.12.1 fdim 함수들 (p: 257)
  • 7.25 타입-제네릭 수학 <tgmath.h> (p: 373-375)
  • F.10.9.1 fdim 함수들 (p: 530)
  • C99 표준 (ISO/IEC 9899:1999):
  • 7.12.12.1 fdim 함수들 (p: 238)
  • 7.22 타입-제네릭 수학 <tgmath.h> (p: 335-337)
  • F.9.9.1 fdim 함수들 (p: 466)

참고 항목

정수 값의 절댓값을 계산합니다 ( |x| )
(함수)
(C99) (C99) (C99)
두 부동 소수점 값 중 더 큰 값을 결정합니다
(함수)