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