1ILOGB(3P)                  POSIX Programmer's Manual                 ILOGB(3P)
2
3
4

PROLOG

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
11       delim $$
12

NAME

14       ilogb, ilogbf, ilogbl — return an unbiased exponent
15

SYNOPSIS

17       #include <math.h>
18
19       int ilogb(double x);
20       int ilogbf(float x);
21       int ilogbl(long double x);
22

DESCRIPTION

24       The functionality described on this reference page is aligned with  the
25       ISO C  standard.  Any  conflict between the requirements described here
26       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2008
27       defers to the ISO C standard.
28
29       These  functions  shall  return  the exponent part of their argument x.
30       Formally, the return value is the integral part of $log sub{r}|x|$ as a
31       signed  integral  value,  for  non-zero  x, where r is the radix of the
32       machine's floating-point arithmetic, which is the  value  of  FLT_RADIX
33       defined in <float.h>.
34
35       An  application  wishing to check for error situations should set errno
36       to zero and  call  feclearexcept(FE_ALL_EXCEPT)  before  calling  these
37       functions. On return, if errno is non-zero or fetestexcept(FE_INVALID |
38       FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero,  an  error  has
39       occurred.
40

RETURN VALUE

42       Upon  successful  completion, these functions shall return the exponent
43       part of x as a signed integer value. They are equivalent to calling the
44       corresponding  logb()  function  and casting the returned value to type
45       int.
46
47       If x is 0, the value FP_ILOGB0 shall be  returned.   On  XSI-conformant
48       systems, a domain error shall occur;
49       otherwise, a domain error may occur.
50
51       If x is ±Inf, the value {INT_MAX} shall be returned.  On XSI-conformant
52       systems, a domain error shall occur;
53       otherwise, a domain error may occur.
54
55       If x is a NaN, the value FP_ILOGBNAN shall be returned.  On XSI-confor‐
56       mant systems, a domain error shall occur;
57       otherwise, a domain error may occur.
58
59       If  the  correct  value is greater than {INT_MAX}, a domain error shall
60       occur and an unspecified value shall be  returned.   On  XSI-conformant
61       systems, a domain error shall occur and {INT_MAX} shall be returned.
62
63       If the correct value is less than {INT_MIN}, a domain error shall occur
64       and an unspecified value shall be returned.  On XSI-conformant systems,
65       a domain error shall occur and {INT_MIN} shall be returned.
66

ERRORS

68       These functions shall fail if:
69
70       Domain Error
71                   The correct value is not representable as an integer.
72
73                   The x argument is zero, NaN, or ±Inf.
74
75                   If  the  integer expression (math_errhandling & MATH_ERRNO)
76                   is non-zero, then errno shall be set  to  [EDOM].   If  the
77                   integer  expression  (math_errhandling & MATH_ERREXCEPT) is
78                   non-zero, then the invalid floating-point  exception  shall
79                   be raised.
80
81       These functions may fail if:
82
83       Domain Error
84                   The x argument is zero, NaN, or ±Inf.
85
86                   If  the  integer expression (math_errhandling & MATH_ERRNO)
87                   is non-zero, then errno shall be set  to  [EDOM].   If  the
88                   integer  expression  (math_errhandling & MATH_ERREXCEPT) is
89                   non-zero, then the invalid floating-point  exception  shall
90                   be raised.
91
92       The following sections are informative.
93

EXAMPLES

95       None.
96

APPLICATION USAGE

98       On   error,   the   expressions  (math_errhandling  &  MATH_ERRNO)  and
99       (math_errhandling & MATH_ERREXCEPT) are independent of each other,  but
100       at least one of them must be non-zero.
101

RATIONALE

103       The  errors come from taking the expected floating-point value and con‐
104       verting it to int, which is an invalid operation  in  IEEE Std 754‐1985
105       (since  overflow,  infinity,  and  NaN  are not representable in a type
106       int), so should be a domain error.
107
108       There are no known implementations that overflow. For overflow to  hap‐
109       pen,  {INT_MAX}  must  be  less  than  LDBL_MAX_EXP*log2(FLT_RADIX)  or
110       {INT_MIN} must be greater than LDBL_MIN_EXP*log2(FLT_RADIX) if  subnor‐
111       mals   are   not   supported,   or   {INT_MIN}  must  be  greater  than
112       (LDBL_MIN_EXP-LDBL_MANT_DIG)*log2(FLT_RADIX)  if  subnormals  are  sup‐
113       ported.
114

FUTURE DIRECTIONS

116       None.
117

SEE ALSO

119       feclearexcept(), fetestexcept(), logb(), scalbln()
120
121       The Base Definitions volume of POSIX.1‐2008, Section 4.19, Treatment of
122       Error Conditions for Mathematical Functions, <float.h>, <math.h>
123
125       Portions of this text are reprinted and reproduced in  electronic  form
126       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
127       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
128       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
129       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
130       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
131       event of any discrepancy between this version and the original IEEE and
132       The  Open Group Standard, the original IEEE and The Open Group Standard
133       is the referee document. The original Standard can be  obtained  online
134       at http://www.unix.org/online.html .
135
136       Any  typographical  or  formatting  errors that appear in this page are
137       most likely to have been introduced during the conversion of the source
138       files  to  man page format. To report such errors, see https://www.ker
139       nel.org/doc/man-pages/reporting_bugs.html .
140
141
142
143IEEE/The Open Group                  2013                            ILOGB(3P)
Impressum