Computes the positive difference between two floating-point numbers.
#include <math.h>
double fdim (x, y)
double x;
double y;
float fdimf (x, y)
float x;
float y;
long double fdiml (x, y)
long double x;
long double y;
_Decimal32 fdimd32 (x, y);
_Decimal32 x;
_Decimal32 y;
_Decimal64 fdimd64 (x, y);
_Decimal64 x;
_Decimal64 y;
_Decimal128 fdimd128 (x, y);
_Decimal128 x;
_Decimal128 y;
The fdim, fdimf, fdiml, fdimd32, fdimd64, and fdimd128 subroutines determine the positive difference between their arguments. If the value of the x parameter is greater than that of the y parameter, x - y is returned. If x is less than or equal to y, +0 is returned.
An application that wants to check for error situations should set the errno global variable to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these subroutines. On return, if the errno is a value of non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is a value of non-zero, an error has occurred.
Item | Description |
---|---|
x | Specifies the value to be computed. |
y | Specifies the value to be computed. |
Upon successful completion, the fdim, fdimf, fdiml, fdimd32, fdimd64, and fdimd128 subroutines return the positive difference value.
If x-y is positive and overflows, a range error occurs and the fdim, fdimf, fdiml, fdimd32, fdimd64, and fdimd128 subroutines return the value of the HUGE_VAL, HUGE_VALF, HUGE_VALL, HUGE_VAL_D32, HUGE_VAL_D64 and HUGE_VAL_D128 macro respectively.
If x-y is positive and underflows, a range error might occur, and 0.0 is returned.
If x or y is NaN, a NaN is returned.