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