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
xis a NaN, a NaN is returned. (garbage in, garbage out, we love consistency π) - If
xis zero, then a pole error occurs, and the functions return-HUGE_VAL,-HUGE_VALF, or-HUGE_VALL, respectively. - If
xis 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:
xis 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
- Copyright 2004, Andries E. Brouwer <aeb@cwi.nl>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms