fabs, fabsf, fabsl - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# fabs, fabsf, fabsl

From cppreference.com
< c‎ | numeric‎ | math

Defined in header `<math.h>` |  |
float fabsf( float arg ); | (1) | (since C99)
double fabs( double arg ); | (2) |
long double fabsl( long double arg ); | (3) | (since C99)
Defined in header `<tgmath.h>` |  |
#define fabs( arg ) | (4) | (since C99)

1-3) Computes the absolute value of a floating point value `arg`.
4) Type-generic macro: If the argument has type long double, `fabsl` is called. Otherwise, if the argument has integer type or has type double, `fabs` is called. Otherwise, `fabsf` is called. If the argument is complex, then the macro invokes the corresponding complex function (cabsf, cabs, cabsl)

### [edit] Parameters

arg | - | floating point value

### [edit] Return value

If successful, returns the absolute value of `arg` (`|arg|`). The value returned is exact and does not depend on any rounding modes.

### [edit] Error handling

This function is not subject to any of the error conditions specified in math_errhandling

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

- If the argument is ±0, +0 is returned
- If the argument is ±∞, +∞ is returned
- If the argument is NaN, NaN is returned

### [edit] Example

Run this code

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

    int main(void)
    {
        printf("fabs(+3) = %f\n", fabs(+3.0));
        printf("fabs(-3) = %f\n", fabs(-3.0));
        // special values
        printf("fabs(-0) = %f\n", fabs(-0.0));
        printf("fabs(-Inf) = %f\n", fabs(-INFINITY));
    }

Output:

    fabs(+3) = 3.000000
    fabs(-3) = 3.000000
    fabs(-0) = 0.000000
    fabs(-Inf) = inf

### [edit] See also

abslabsllabs (C99) | computes absolute value of an integral value (|x|) (function) [edit]
copysigncopysignfcopysignl (C99)(C99)(C99) | produces a value with the magnitude of a given value and the sign of another given value (function) [edit]
signbit (C99) | checks if the given number is negative (function) [edit]
cabscabsfcabsl (C99)(C99)(C99) | computes the magnitude of a complex number (function) [edit]
C++ documentation for fabs

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/numeric/math/fabs&oldid=71303"