| 1 |
'\" t |
| 2 |
.\" Copyright 2004, Andries E. Brouwer <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH logb 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
logb, logbf, logbl \- get exponent of a floating-point value |
| 10 |
.SH LIBRARY |
| 11 |
Math library |
| 12 |
.RI ( libm ,\~ \-lm ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <math.h> |
| 16 |
.P |
| 17 |
.BI "double logb(double " x ); |
| 18 |
.BI "float logbf(float " x ); |
| 19 |
.BI "long double logbl(long double " x ); |
| 20 |
.fi |
| 21 |
.P |
| 22 |
.RS -4 |
| 23 |
Feature Test Macro Requirements for glibc (see |
| 24 |
.BR feature_test_macros (7)): |
| 25 |
.RE |
| 26 |
.P |
| 27 |
.BR logb (): |
| 28 |
.nf |
| 29 |
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
| 30 |
|| _XOPEN_SOURCE >= 500 |
| 31 |
.\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED |
| 32 |
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE |
| 33 |
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE |
| 34 |
.fi |
| 35 |
.P |
| 36 |
.BR logbf (), |
| 37 |
.BR logbl (): |
| 38 |
.nf |
| 39 |
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
| 40 |
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE |
| 41 |
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE |
| 42 |
.fi |
| 43 |
.SH DESCRIPTION |
| 44 |
These functions extract the exponent from the |
| 45 |
internal floating-point representation of |
| 46 |
.I x |
| 47 |
and return it as a floating-point value. |
| 48 |
The integer constant |
| 49 |
.BR FLT_RADIX , |
| 50 |
defined in |
| 51 |
.IR <float.h> , |
| 52 |
indicates the radix used for the system's floating-point representation. |
| 53 |
If |
| 54 |
.B FLT_RADIX |
| 55 |
is 2, |
| 56 |
.BI logb( x ) |
| 57 |
is similar to |
| 58 |
.BI floor(log2(fabs( x )))\f[R],\f[] |
| 59 |
except that the latter may give an incorrect integer |
| 60 |
due to intermediate rounding. |
| 61 |
.P |
| 62 |
If |
| 63 |
.I x |
| 64 |
is subnormal, |
| 65 |
.BR logb () |
| 66 |
returns the exponent |
| 67 |
.I x |
| 68 |
would have if it were normalized. |
| 69 |
.SH RETURN VALUE |
| 70 |
On success, these functions return the exponent of |
| 71 |
.IR x . |
| 72 |
.P |
| 73 |
If |
| 74 |
.I x |
| 75 |
is a NaN, |
| 76 |
a NaN is returned. |
| 77 |
.P |
| 78 |
If |
| 79 |
.I x |
| 80 |
is zero, then a pole error occurs, and the functions return |
| 81 |
.RB \- HUGE_VAL , |
| 82 |
.RB \- HUGE_VALF , |
| 83 |
or |
| 84 |
.RB \- HUGE_VALL , |
| 85 |
respectively. |
| 86 |
.P |
| 87 |
If |
| 88 |
.I x |
| 89 |
is negative infinity or positive infinity, then |
| 90 |
positive infinity is returned. |
| 91 |
.SH ERRORS |
| 92 |
See |
| 93 |
.BR math_error (7) |
| 94 |
for information on how to determine whether an error has occurred |
| 95 |
when calling these functions. |
| 96 |
.P |
| 97 |
The following errors can occur: |
| 98 |
.TP |
| 99 |
Pole error: \f[I]x\f[] is 0 |
| 100 |
.\" .I errno |
| 101 |
.\" is set to |
| 102 |
.\" .BR ERANGE . |
| 103 |
A divide-by-zero floating-point exception |
| 104 |
.RB ( FE_DIVBYZERO ) |
| 105 |
is raised. |
| 106 |
.P |
| 107 |
These functions do not set |
| 108 |
.IR errno . |
| 109 |
.\" FIXME . Is it intentional that these functions do not set errno? |
| 110 |
.\" log(), log2(), log10() do set errno |
| 111 |
.\" Bug raised: https://www.sourceware.org/bugzilla/show_bug.cgi?id=6793 |
| 112 |
.\" |
| 113 |
.SH ATTRIBUTES |
| 114 |
For an explanation of the terms used in this section, see |
| 115 |
.BR attributes (7). |
| 116 |
.TS |
| 117 |
allbox; |
| 118 |
lbx lb lb |
| 119 |
l l l. |
| 120 |
Interface Attribute Value |
| 121 |
T{ |
| 122 |
.na |
| 123 |
.nh |
| 124 |
.BR logb (), |
| 125 |
.BR logbf (), |
| 126 |
.BR logbl () |
| 127 |
T} Thread safety MT-Safe |
| 128 |
.TE |
| 129 |
.SH STANDARDS |
| 130 |
C11, POSIX.1-2008. |
| 131 |
.SH HISTORY |
| 132 |
C99, POSIX.1-2001. |
| 133 |
.TP |
| 134 |
.BR logb () |
| 135 |
4.3BSD |
| 136 |
(see IEEE.3 in the 4.3BSD manual). |
| 137 |
.SH SEE ALSO |
| 138 |
.BR ilogb (3), |
| 139 |
.BR log (3) |