Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#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);
The fabs() functions calculate the absolute value of a floating-point argument.
Returns the absolute value of the float input.
/* 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);
}
fabs( -5.679800 ) = 5.679800