ILOGB(3P)
π PROLOG π
okay bestie, before we even start, housekeeping β¨ this page is part of the POSIX Programmer's Manual. And likeβ¦ the Linux implementation of this interface may differ (so go check the corresponding Linux manual page for the deets on Linux behavior, fr), or the interface might not even be implemented on Linux at all. π so don't come for me if it's giving nothing on your machine.
π NAME π
ilogb, ilogbf, ilogbl β return an unbiased exponent
so it's the ilogb girlies, coming to you straight from the POSIX Programmer's Manual (3P, iykyk) π
β¨ SYNOPSIS β¨
#include <math.h>
int ilogb(double x);
int ilogbf(float x);
int ilogbl(long double x);
πΈ DESCRIPTION πΈ
okay so real talk: everything described on this reference page is aligned with the ISO C standard. If anything here conflicts with the ISO C standard, that was not the vibe and it's unintentional. This volume of POSIX.1β2017 just defers to the ISO C standard, periodt.
These functions shall return the exponent part of their argument x. Formally, the return value is the integral part of log<sub>r</sub>|x| as a signed integral value, for non-zero x, where r is the radix of the machine's floating-point arithmetic β which is the value of FLT_RADIX defined in <float.h>. π
An application wishing to check for error situations should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. On return, if errno is non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred. π¨
π RETURN VALUE π
Upon successful completion, these functions shall return the exponent part of x as a signed integer value. They are equivalent to calling the corresponding logb() function and casting the returned value to type int.
- If
xis0, the valueFP_ILOGB0shall be returned. On XSI-conformant systems, a domain error shall occur; otherwise, a domain error may occur. - If
xisΒ±Inf, the value{INT_MAX}shall be returned. On XSI-conformant systems, a domain error shall occur; otherwise, a domain error may occur. - If
xis aNaN, the valueFP_ILOGBNANshall be returned. On XSI-conformant systems, a domain error shall occur; otherwise, a domain error may occur. - If the correct value is greater than
{INT_MAX}, a domain error shall occur and an unspecified value shall be returned. On XSI-conformant systems, a domain error shall occur and{INT_MAX}shall be returned. - If the correct value is less than
{INT_MIN}, a domain error shall occur and an unspecified value shall be returned. On XSI-conformant systems, a domain error shall occur and{INT_MIN}shall be returned.
like bestie, "unspecified value" is literally the function saying idk go ask someone else π
π₯ ERRORS π₯
These functions shall fail if:
- Domain Error β The correct value is not representable as an integer.
The x argument is zero, NaN, or Β±Inf.
If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [EDOM]. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the invalid floating-point exception shall be raised.
These functions may fail if:
- Domain Error β The
xargument is zero,NaN, orΒ±Inf.
If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [EDOM]. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the invalid floating-point exception shall be raised.
The following sections are informative. π
π¦ EXAMPLES π¦
None.
β¦yeah bestie, literally none. the void. nothing. π³οΈ iconic behavior honestly.
π APPLICATION USAGE π
On error, the expressions (math_errhandling & MATH_ERRNO) and (math_errhandling & MATH_ERREXCEPT) are independent of each other, but at least one of them must be non-zero. no cap.
π RATIONALE π
The errors come from taking the expected floating-point value and converting it to int, which is an invalid operation in IEEE Std 754β1985 (since overflow, infinity, and NaN are not representable in a type int), so it should be a domain error.
There are no known implementations that overflow. For overflow to happen, {INT_MAX} must be less than LDBL_MAX_EXP*log2(FLT_RADIX) or {INT_MIN} must be greater than LDBL_MIN_EXP*log2(FLT_RADIX) if subnormals are not supported, or {INT_MIN} must be greater than (LDBL_MIN_EXP-LDBL_MANT_DIG)*log2(FLT_RADIX) if subnormals are supported.
so basically: this overflow scenario is the unicorn of the math library. everyone's heard of it, nobody's seen it. π¦
π§ FUTURE DIRECTIONS π§
None.
β SEE ALSO β
feclearexcept()fetestexcept()logb()scalbln()
The Base Definitions volume of POSIX.1β2017, Section 4.20, Treatment of Error Conditions for Mathematical Functions, <float.h>, <math.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's a wrap bestie π this whole thing came to you courtesy of IEEE/The Open Group, 2017 β ILOGB(3P), slaying since forever. go forth and compute your exponents, you absolute legend π«Άβ¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- 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-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms