On this page
fabs
Prev: sqrt | Up: math.h | Next: pow
Rel: math.h, abs()
Ref: cppreference — fabs
Tags: #public #prog #c #stdlib #math #tier/core
Include
#include <math.h>
Signature & Overview
double fabs(double x);
Returns the absolute value of a floating-point number (never use integer abs() on floats).
Notes & Pitfalls
- Floating-point absolute value: Use
fabs()fordouble,fabsf()forfloat, andabs()(<stdlib.h>) forint. Link with-lmon Linux.
Example
#include <assert.h>
#include <math.h>
int main(void) { assert(fabs(-3.5) == 3.5); }
Linked from
Related notes
- tuts/c/stdlib/math/pow Linked here; links to this page; shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/math/sqrt Linked here; links to this page; shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/math Linked here; links to this page; shared tags: #c, #math, #prog, #stdlib
- tuts/c/stdlib/stdlib/abs Linked here; shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/math/floor shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/math/isnan shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/static_assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isalpha shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isdigit shared tags: #c, #prog, #stdlib, #tier