fabs function(Absolute Value of Floating-Point Number) in C Language – example and detail

In the C Programming Language, the fabs feature returns the absolute value of a floating-point number.

Syntax

The syntax for the fabs characteristic in the C Language is:

double fabs(double x);

Parameters or Arguments

x

The value to convert to an absolute value.

Returns

The fabs feature returns the absolute cost of a floating-point wide variety represented by x.

Required Header

In the C Language, the required header for the fabs feature is:

#include <math.h>

Applies To

In the C Language, the fabs characteristic can be used in the following versions:

ANSI/ISO 9899-1990

fabs Example

/* Example using fabs by TechOnTheNet.com */

#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[])
{
    /* Define temporary variables */
    double value;
    double result;

    /* Assign the value we will find the fabs of */
    value = -2.1;

    /* Calculate the absolute value of value */
    result = fabs(value);

    /* Display the result of the calculation */
    printf("The Absolute Value of %f is %f\n", value, result);

    return 0;
}

When compiled and run, this application will output:

The Absolute Value of -2.100000 is 2.100000

Similar Functions

Other C features that are similar to the fabs function:

abs function <stdlib.h>

labs function <stdlib.h>