Name | Description | Notes | Source | Availability | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
abs() |
Compute absolute value | (·) | <stdlib.h> |
C89 | C90 | C95 | C99 | C11 | |||
cabs() |
Compute absolute value | ? | (·) | <complex.h> |
C99 | C11 | |||||
cabsf() |
Compute absolute value | ? | (·) | <complex.h> |
C99 | C11 | |||||
cabsl() |
Compute absolute value | ? | (·) | <complex.h> |
C99 | C11 | |||||
fabs() |
Compute absolute value | (·) | <math.h> |
C89 | C90 | C95 | C99 | C11 | |||
fabs() |
Compute absolute value | M | (·) | <tgmath.h> |
C99 | C11 | |||||
fabsf() |
Compute absolute value | (·) | <math.h> |
C99 | C11 | ||||||
fabsl() |
Compute absolute value | (·) | <math.h> |
C99 | C11 | ||||||
imaxabs() |
Compute absolute value | (·) | <inttypes.h> |
C11 | |||||||
labs() |
Compute absolute value | (·) | <stdlib.h> |
C89 | C90 | C95 | C99 | C11 | |||
llabs() |
Compute absolute value | (·) | <stdlib.h> |
C99 | C11 |
The absolute value of a positive real number is itself. The absolute value of a negative real number is itself negated, which is a positive real number. The absolute value of zero is zero. The absolute value of a complex number is its distance from the origin, which is a non-negative real number.
The following C functions are available to compute absolute values:
#include <stdlib.h>
int abs(int);
long labs(long);
long long llabs(long long);
#include <inttypes.h>
intmax_t imaxabs(intmax_t);
#include <math.h>
float fabsf(float);
double fabs(double);
long double fabsl(long double);
#include <complex.h>
float cabsf(float complex);
double cabs(double complex);
long double cabsl(long double complex);
#include <tgmath.h>
real-floating-type fabs(floating-type);
For example, fabs(10.0)
and fabs(-10.0)
both yield 10.0
.