1ILOGB(P) POSIX Programmer's Manual ILOGB(P)
2
3
4
6 ilogb, ilogbf, ilogbl - return an unbiased exponent
7
9 #include <math.h>
10
11 int ilogb(double x);
12 int ilogbf(float x);
13 int ilogbl(long double x);
14
15
17 These functions shall return the exponent part of their argument x.
18 Formally, the return value is the integral part of log_r|x| as a signed
19 integral value, for non-zero x, where r is the radix of the machine's
20 floating-point arithmetic, which is the value of FLT_RADIX defined in
21 <float.h>.
22
23 An application wishing to check for error situations should set errno
24 to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
25 functions. On return, if errno is non-zero or fetestexcept(FE_INVALID
26 | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
27 occurred.
28
30 Upon successful completion, these functions shall return the exponent
31 part of x as a signed integer value. They are equivalent to calling the
32 corresponding logb() function and casting the returned value to type
33 int.
34
35 If x is 0, a domain error shall occur, and the value FP_ILOGB0 shall
36 be returned.
37
38 If x is ±Inf, a domain error shall occur, and the value {INT_MAX}
39 shall be returned.
40
41 If x is a NaN, a domain error shall occur, and the value FP_ILOGBNAN
42 shall be returned.
43
44 If the correct value is greater than {INT_MAX}, {INT_MAX} shall be
45 returned and a domain error shall occur.
46
47 If the correct value is less than {INT_MIN}, {INT_MIN} shall be
48 returned and a domain error shall occur.
49
51 These functions shall fail if:
52
53 Domain Error
54 The x argument is zero, NaN, or ±Inf, or the correct value is
55 not representable as an integer.
56
57 If the integer expression (math_errhandling & MATH_ERRNO) is non-zero,
58 then errno shall be set to [EDOM]. If the integer expression
59 (math_errhandling & MATH_ERREXCEPT) is non-zero, then the invalid
60 floating-point exception shall be raised.
61
62
63 The following sections are informative.
64
66 None.
67
69 On error, the expressions (math_errhandling & MATH_ERRNO) and
70 (math_errhandling & MATH_ERREXCEPT) are independent of each other, but
71 at least one of them must be non-zero.
72
74 The errors come from taking the expected floating-point value and con‐
75 verting it to int, which is an invalid operation in IEEE Std 754-1985
76 (since overflow, infinity, and NaN are not representable in a type
77 int), so should be a domain error.
78
79 There are no known implementations that overflow. For overflow to hap‐
80 pen, {INT_MAX} must be less than LDBL_MAX_EXP*log2(FLT_RADIX) or
81 {INT_MIN} must be greater than LDBL_MIN_EXP*log2(FLT_RADIX) if subnor‐
82 mals are not supported, or {INT_MIN} must be greater than
83 (LDBL_MIN_EXP-LDBL_MANT_DIG)*log2(FLT_RADIX) if subnormals are sup‐
84 ported.
85
87 None.
88
90 feclearexcept() , fetestexcept() , logb() , scalb() , the Base Defini‐
91 tions volume of IEEE Std 1003.1-2001, Section 4.18, Treatment of Error
92 Conditions for Mathematical Functions, <float.h>, <math.h>
93
95 Portions of this text are reprinted and reproduced in electronic form
96 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
97 -- Portable Operating System Interface (POSIX), The Open Group Base
98 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
99 Electrical and Electronics Engineers, Inc and The Open Group. In the
100 event of any discrepancy between this version and the original IEEE and
101 The Open Group Standard, the original IEEE and The Open Group Standard
102 is the referee document. The original Standard can be obtained online
103 at http://www.opengroup.org/unix/online.html .
104
105
106
107IEEE/The Open Group 2003 ILOGB(P)