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 x is a NaN, a NaN is returned. (NaN in, NaN out, the cycle continues πŸŒ€)
  • if x is -0, +0 is returned. yes bestie, negative zero is real and this function does NOT respect it 😭
  • if x is 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 double also 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms