fabs - C math.h

C examples for math.h:fabs

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Returns the absolute value of x: |x|.

Prototype

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

Parameters

Parameter Description
x Value whose absolute value is returned.

Return Value

The absolute value of x.

Example

Demo Code


#include <stdio.h>
#include <math.h> /* fabs */

int main ()/*from   w  w  w  .j av a 2  s  . c o m*/
{
  printf ("%f\n", fabs (3.1416) );
  printf ("%f\n", fabs (-10.6) );
  printf ("%f\n", fabs (-0.6) );
  printf ("%f\n", fabs (-0.0) );
  return 0;
}

Related Tutorials