fabs()

Computes an absolute value.

  #include <math.h>
  
  double fabs(double x);
  
  float fabsf(float x);
   
  long double fabsl(long double x);    
Parameter

x

A value from which to compute.

Remarks

These functions return the absolute value of x.

This facility may not be available on configurations of the EWL that run on platforms that do not have floating-point math capabilities.

Listing: Example of fabs() usage

#include <math.h>

#include <stdio.h>

int main(void)

{

double s = -5.0, t = 5.0;

printf("Absolute value of %f is %f.\n", s, fabs(s));

printf("Absolute value of %f is %f.\n", t, fabs(t));

return 0;

}

Output:

Absolute value of -5.000000 is 5.000000.

Absolute value of 5.000000 is 5.000000.