LOGB(3POSIX)

πŸ’– LOGB(3POSIX) β€” the POSIX Programmer's Manual glow-up πŸ’–

okay bestie, we're diving into LOGB(3POSIX), straight out of the POSIX Programmer's Manual. buckle up, it's math o'clock πŸŽ€


🌸 PROLOG 🌸

This manual page is part of the POSIX Programmer's Manual. Heads up though β€” the Linux implementation of this interface may be different (so like, go check the matching Linux manual page for the tea β˜•), or honestly the interface might not even be implemented on Linux at all. πŸ’€


✨ NAME ✨

logb, logbf, logbl β€” radix-independent exponent πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

#include <math.h>

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

three flavors, one vibe. pick your precision, queen πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

Everything on this page is aligned with the ISO C standard. If anything here ever conflicts with ISO C, that's 100% not on purpose, ok? This volume of POSIX.1‐2017 just defers to the ISO C standard, periodt.

So what do these functions actually do? They compute the exponent of x β€” which is the integral part of log<sub>r</sub> |x|, handed back as a signed floating-point value, and only for non-zero x. and r? that's the radix of the machine's floating-point arithmetic, which is literally the value of FLT_RADIX defined in the <float.h> header. iykyk 🌈

If x is subnormal, it gets treated as though it were normalized instead. so for finite positive x:

1 <= x * FLT_RADIX-logb(x) < FLT_RADIX

and if you're the kind of app that wants to actually check for error situations? you should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. then on return, if errno is non-zero, or if fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, then bestie… an error has occurred 😭


🌟 RETURN VALUE 🌟

Upon successful completion, these functions return the exponent of x. slay.

If x is Β±0, then:

  • logb(), logbf(), and logbl() shall return -HUGE_VAL, -HUGE_VALF, and -HUGE_VALL, respectively.

On systems that support the IEC 60559 Floating-Point option, a pole error shall occur. Otherwise, a pole error may occur. πŸ™ˆ

If x is NaN, a NaN shall be returned.

If x is Β±Inf, +Inf shall be returned.


πŸ”₯ ERRORS πŸ”₯

These functions shall fail if:

  • Pole Error β€” the value of x is Β±0.
    • If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [ERANGE].
    • If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the divide-by-zero floating-point exception shall be raised.

These functions may fail if:

  • Pole Error β€” the value of x is 0.
    • If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [ERANGE].
    • If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the divide-by-zero floating-point exception shall be raised.

The following sections are informative. (translation: the required stuff is done, everything below is bonus content 🫢)


🧚 EXAMPLES 🧚

None. literally none. the void. empty. πŸ’€


πŸ’œ 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 🌈

None. iconic of them honestly πŸ‘‘


⭐ FUTURE DIRECTIONS ⭐

None. the future is a blank canvas bestie πŸ¦‹


πŸ“ SEE ALSO πŸ“

  • feclearexcept()
  • fetestexcept()
  • ilogb()
  • scalbln()

The Base Definitions volume of POSIX.1‐2017:

  • Section 4.20, Treatment of Error Conditions for Mathematical Functions
  • <float.h>
  • <math.h>

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 the whole page, bestie πŸ’– brought to you by IEEE/The Open Group, 2017 β€” aka the footer, aka the little signature at the bottom that says we're done here. go forth and compute those exponents, you absolute main character ✨πŸ’