6.11.86 ilogbl Function
Calculates the signed integer exponent of a long double precision floating-point value.
Include
<math.h>
Prototype
int ilogbl(long double x);
Argument
x
- any positive value for which to return the exponent
Return Value
Returns the exponent of x
as a signed integer value. If
x
is 0, it returns the value FP_ILOGB0
; if
x
is infinite, it returns the value INT_MAX
; if
x
is a NaN it returns the value FP_ILOGBNAN
;
otherwise, this will yield the same value as the corresponding logb
function cast to type int
.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <math.h>
#include <stdio.h>
#include <errno.h>
int main(void)
{
double x;
int y;
errno = 0;
x = 13.45;
y = ilogbl(x);
if (errno)
perror("Error");
printf("The exponent of %f is %d\n", x, y);
errno = 0;
x = 0.0;
y = ilogbl(x);
if (errno)
perror("Error");
printf("The exponent of %f is %d\n", x, y);
errno = 0;
x = -2.0;
y = ilogbl(x);
if (errno)
perror("Error");
printf("The exponent of %f is %d\n", x, y);
}
Example Output
The exponent of 13.450000 is 3
The exponent of 0.000000 is -2147483648
The exponent of -2.000000 is 1