Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

fabs, fabsf, fabsl - Absolute value of a floating-point number

&pagelevel(4)&pagelevel

Definition  

#include <math.h>

double fabs(double x);
float fabsf(float x); (C11)
long double fabsl(long double x); (C11)

These functions calculate the absolute value of a floating-point number x.

Return val.

Absolute value of the argument: |x|

Example

The following program calculates the absolute value of a floating-point number entered:

#include <math.h>
#include <stdio.h>
int main(void)
{
   double x;
   printf("Please enter a floating-point number:\n");
   if (scanf("%lf", &x) == 1)
       printf("?%g? = %g\n", x, fabs(x));
   return 0;
}

See also

abs, cabs, ceil, floor, labs, llabs