fabs(), fabsf(), fabsl() — Calculate floating-point absolute value
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C
POSIX.1 XPG4 XPG4.2 ISO/ANSI C++ C99 Single UNIX Specification, Version 3 C++ TR1 C99 |
both |
Format
#include <math.h>
double fabs(double x);
float fabs(float x); /* C++ only */
long double fabs(long double x); /* C++ only */
float fabsf(float x);
long double fabsl(long double x);
General description
The fabs() functions calculate the absolute value of a floating-point argument.
Note: These
functions work in both IEEE Binary Floating-Point and hexadecimal
floating-point formats. See IEEE binary floating-point for
more information about IEEE Binary Floating-Point.
Returned value
Returns the absolute value of the float input.
Example
/* This example calculates y as the absolute value of x. */
#include <math.h>
int main(void)
{
double x, y;
x = -5.6798;
y = fabs(x);
printf("fabs( %f ) = %f\n", x, y);
}
Output
fabs( -5.679800 ) = 5.679800