1ILOGB(3P) POSIX Programmer's Manual ILOGB(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 ilogb, ilogbf, ilogbl — return an unbiased exponent
13
15 #include <math.h>
16
17 int ilogb(double x);
18 int ilogbf(float x);
19 int ilogbl(long double x);
20
22 The functionality described on this reference page is aligned with the
23 ISO C standard. Any conflict between the requirements described here
24 and the ISO C standard is unintentional. This volume of POSIX.1‐2017
25 defers to the ISO C standard.
26
27 These functions shall return the exponent part of their argument x.
28 Formally, the return value is the integral part of logr|x| as a signed
29 integral value, for non-zero x, where r is the radix of the machine's
30 floating-point arithmetic, which is the value of FLT_RADIX defined in
31 <float.h>.
32
33 An application wishing to check for error situations should set errno
34 to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
35 functions. On return, if errno is non-zero or fetestexcept(FE_INVALID |
36 FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
37 occurred.
38
40 Upon successful completion, these functions shall return the exponent
41 part of x as a signed integer value. They are equivalent to calling the
42 corresponding logb() function and casting the returned value to type
43 int.
44
45 If x is 0, the value FP_ILOGB0 shall be returned. On XSI-conformant
46 systems, a domain error shall occur;
47 otherwise, a domain error may occur.
48
49 If x is ±Inf, the value {INT_MAX} shall be returned. On XSI-conformant
50 systems, a domain error shall occur;
51 otherwise, a domain error may occur.
52
53 If x is a NaN, the value FP_ILOGBNAN shall be returned. On XSI-confor‐
54 mant systems, a domain error shall occur;
55 otherwise, a domain error may occur.
56
57 If the correct value is greater than {INT_MAX}, a domain error shall
58 occur and an unspecified value shall be returned. On XSI-conformant
59 systems, a domain error shall occur and {INT_MAX} shall be returned.
60
61 If the correct value is less than {INT_MIN}, a domain error shall occur
62 and an unspecified value shall be returned. On XSI-conformant systems,
63 a domain error shall occur and {INT_MIN} shall be returned.
64
66 These functions shall fail if:
67
68 Domain Error
69 The correct value is not representable as an integer.
70
71 The x argument is zero, NaN, or ±Inf.
72
73 If the integer expression (math_errhandling & MATH_ERRNO)
74 is non-zero, then errno shall be set to [EDOM]. If the
75 integer expression (math_errhandling & MATH_ERREXCEPT) is
76 non-zero, then the invalid floating-point exception shall
77 be raised.
78
79 These functions may fail if:
80
81 Domain Error
82 The x argument is zero, NaN, or ±Inf.
83
84 If the integer expression (math_errhandling & MATH_ERRNO)
85 is non-zero, then errno shall be set to [EDOM]. If the
86 integer expression (math_errhandling & MATH_ERREXCEPT) is
87 non-zero, then the invalid floating-point exception shall
88 be raised.
89
90 The following sections are informative.
91
93 None.
94
96 On error, the expressions (math_errhandling & MATH_ERRNO) and
97 (math_errhandling & MATH_ERREXCEPT) are independent of each other, but
98 at least one of them must be non-zero.
99
101 The errors come from taking the expected floating-point value and con‐
102 verting it to int, which is an invalid operation in IEEE Std 754‐1985
103 (since overflow, infinity, and NaN are not representable in a type
104 int), so should be a domain error.
105
106 There are no known implementations that overflow. For overflow to hap‐
107 pen, {INT_MAX} must be less than LDBL_MAX_EXP*log2(FLT_RADIX) or
108 {INT_MIN} must be greater than LDBL_MIN_EXP*log2(FLT_RADIX) if subnor‐
109 mals are not supported, or {INT_MIN} must be greater than
110 (LDBL_MIN_EXP-LDBL_MANT_DIG)*log2(FLT_RADIX) if subnormals are sup‐
111 ported.
112
114 None.
115
117 feclearexcept(), fetestexcept(), logb(), scalbln()
118
119 The Base Definitions volume of POSIX.1‐2017, Section 4.20, Treatment of
120 Error Conditions for Mathematical Functions, <float.h>, <math.h>
121
123 Portions of this text are reprinted and reproduced in electronic form
124 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
125 table Operating System Interface (POSIX), The Open Group Base Specifi‐
126 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
127 Electrical and Electronics Engineers, Inc and The Open Group. In the
128 event of any discrepancy between this version and the original IEEE and
129 The Open Group Standard, the original IEEE and The Open Group Standard
130 is the referee document. The original Standard can be obtained online
131 at http://www.opengroup.org/unix/online.html .
132
133 Any typographical or formatting errors that appear in this page are
134 most likely to have been introduced during the conversion of the source
135 files to man page format. To report such errors, see https://www.ker‐
136 nel.org/doc/man-pages/reporting_bugs.html .
137
138
139
140IEEE/The Open Group 2017 ILOGB(3P)