fabs(3)
π fabs β bestie's guide to absolute value π
okay so. picture this: you've got a floating-point number and it's being dramatic about its sign, and you just want the magnitude, the raw unfiltered distance-from-zero energy. that's what fabs, fabsf, and fabsl are for. they live in the math library, libm, so you link with -lm and you're good. no cap.
β¨ SYNOPSIS β¨
#include <math.h>
double fabs(double x);
float fabsf(float x);
long double fabsl(long double x);
π Feature Test Macro Requirements for glibc
(if you wanna know how this whole system works, go read feature_test_macros(7), it's giving lore)
fabsf(), fabsl():
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
so basically if you're on modern glibc it just works, and if you're on old glibc you need one of those legacy macros. either way you're covered π
πΈ DESCRIPTION πΈ
these three functions hand you back the absolute value of the floating-point number x. that's it. that's the whole job. they take whatever sign drama x is going through and justβ¦ let it go. β¨
π RETURN VALUE π
they return the absolute value of x. iconic. but here's the fine print, because edge cases are always the main character:
- if
xis a NaN, a NaN is returned. (NaN in, NaN out, the cycle continues π) - if
xis-0,+0is returned. yes bestie, negative zero is real and this function does NOT respect it π - if
xis negative infinity or positive infinity, positive infinity is returned. infinity stays winning fr fr.
π ERRORS π
No errors occur.
literally nothing can go wrong here. it's the safest function in the whole library. zero drama, zero errno, just vibes π
π¦ ATTRIBUTES π¦
okay so if you wanna know what all these fancy terms even mean, attributes(7) has you covered.
fabs(),fabsf(),fabsl()β Thread safety: MT-Safe π
translation: you can call these from multiple threads and they will NOT fight each other. team players. π«Ά
β STANDARDS β
C11, POSIX.1-2008.
certified, standardized, official. periodt. π
π§ HISTORY π§
- C99, POSIX.1-2001.
- The variant returning
doublealso conforms to SVr4, 4.3BSD, C89.
so the double one has been doing this since forever. it was serving absolute value before it was cool. a true veteran π
π SEE ALSO π
(the whole math-function friend group, go say hi πΈ)
anyway that's the whole page bestie, no skips, no skims, every single detail preserved because that's the assignment π
this came straight out of Linux man-pages 6.20, dated 2026-02-08. slay, go take some absolute values. πβ¨
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms