logb(3)

✨ logb β€” get exponent of a floating-point value ✨

okay bestie, so this is logb(3) from the Library Functions Manual, and it's literally just "girl, what's your exponent?" but for floats πŸ’…


🌸 NAME 🌸

logb, logbf, logbl β€” get exponent of a floating-point value

πŸ“š LIBRARY πŸ“š

Math library (that's libm, so link with -lm bestie, don't forget or the linker will be SO dramatic)

πŸŽ€ SYNOPSIS πŸŽ€

#include <math.h>

double logb(double x);
float logbf(float x);
long double logbl(long double x);

πŸ’– Feature Test Macro Requirements for glibc πŸ’–

(yes, peep feature_test_macros(7) if you're confused, she explains everything)

logb():

_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
    || _XOPEN_SOURCE >= 500
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
    || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

logbf(), logbl():

_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
    || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the way this works πŸ‘‘ these functions extract the exponent straight out of x's internal floating-point representation and hand it back to you as a floating-point value. no cap, that's it, that's the whole job.

the integer constant FLT_RADIX, which lives in <float.h>, tells you the radix your system's floating-point representation is using. if FLT_RADIX is 2, then logb(x) is similar to floor(log2(fabs(x))) β€” but bestie, hear me: the latter can give you a straight-up incorrect integer because of intermediate rounding 😭 so don't be out here swapping them like they're the same thing, because they are NOT.

and the iconic part: if x is subnormal, logb() returns the exponent x would have if it were normalized. it's giving "the version of me that got the glow-up" ✨


⭐ RETURN VALUE ⭐

On success, these functions return the exponent of x.

  • If x is a NaN, a NaN is returned. (garbage in, garbage out, we love consistency πŸ’€)
  • If x is zero, then a pole error occurs, and the functions return -HUGE_VAL, -HUGE_VALF, or -HUGE_VALL, respectively.
  • If x is negative infinity or positive infinity, then positive infinity is returned.

πŸ”₯ ERRORS πŸ”₯

peep math_error(7) for the tea on how to figure out whether an error actually happened when you called these functions, bestie.

here's what can go down:

  • Pole error: x is 0 β€” a divide-by-zero floating-point exception (FE_DIVBYZERO) is raised.
🫢 IMPORTANT: These functions do not set errno. not a single one. so don't go checking it, she's not talking.

πŸ’… ATTRIBUTES πŸ’…

for an explanation of the terms used in this section, see attributes(7).

  • logb(), logbf(), logbl() β€” Thread safety: MT-Safe (we stan a thread-safe queen πŸ‘‘)

🌈 STANDARDS 🌈

C11, POSIX.1-2008.

πŸ•°οΈ HISTORY πŸ•°οΈ

C99, POSIX.1-2001.

logb() is out here serving since 4.3BSD β€” see IEEE.3 in the 4.3BSD manual if you wanna see the original slay.


πŸ‘€ SEE ALSO πŸ‘€


okay that's the whole page, you ate that πŸ“ this was Linux man-pages version 6.20, dated 2026-02-08, and it's still logb(3) at the end of the day. go take the exponent of something, bestie πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ 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