Next: lrint, Previous: log2, Up: Math [Contents][Index]

### 1.38 `logb`, `logbf`—get exponent of floating-point number

Synopsis

    #include <math.h>
    double logb(double x);
    float logbf(float x);

Description
The `logb` functions extract the exponent of x, as a signed integer value in floating-point format. If x is subnormal it is treated as though it were normalized; thus, for positive finite x, 1 <= (x * FLT_RADIX to the power (-logb(x))) < FLT_RADIX. A domain error may occur if the argument is zero. In this floating-point implementation, FLT_RADIX is 2. Which also means that for finite x, `logb`(x) = `floor`(`log2`(`fabs`(x))).

All nonzero, normal numbers can be described as m * 2**p, where 1.0 <= m < 2.0. The `logb` functions examine the argument x, and return p. The `frexp` functions are similar to the `logb` functions, but returning m adjusted to the interval [.5, 1) or 0, and p+1.

Returns
When x is:
+inf or -inf, +inf is returned;
NaN, NaN is returned;
0, -inf is returned, and the divide-by-zero exception is raised;
otherwise, the `logb` functions return the signed exponent of x.

Portability
ANSI C, POSIX

See Also
frexp, ilogb