fabs
Return the absolute value of the input floating point number.
Interface Definition
C interface:
float fabsf(float x);
double fabs(double x);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of the input data. |
Input |
Return Value
- If input x is ±0, the return value is +0.
- If input x is ±∞, the return value is +∞.
- If input x is ±NaN, the return value is NaN.
Dependency
C: "km.h"
Example
C interface:
// typical usage
printf("fabs(1.0) = %.15f\n", fabs(1.0));
printf("fabs(-3.0) = %.15f\n", fabs(-3.0));
// special handing
printf("fabs(NAN) = %.15f\n", fabs(NAN));
printf("fabs(-NAN) = %.15f\n", fabs(-NAN));
printf("fabs(INFINITY) = %.15f\n", fabs(INFINITY));
printf("fabs(-INFINITY) = %.15f\n", fabs(-INFINITY));
result
/*
* fabs(1.0) = 1.000000000000000
* fabs(-3.0) = 3.000000000000000
* fabs(NAN) = nan
* fabs(-NAN) = nan
* fabs(INFINITY) = inf
* fabs(-INFINITY) = inf
* */
Parent topic: Miscellaneous Functions