Compute the radix-independent exponent
#include <math.h> double logb ( double x ); float logbf ( float x );
The logb() and logbf() functions compute the exponent part of x, which is the integral part of:
logr |x|
as a signed floating point value, for nonzero finite x, where r is the radix of the machine's floating point arithmetic.
The binary exponent of x, a signed integer converted to double-precision floating-point.
| If x is: | logb() returns: |
|---|---|
| 0.0 | -HUGE_VAL (errno is set to EDOM) |
| <0.0 | -HUGE_VAL (errno may be set to ERANGE) |
| ±infinity | +infinity |
#include <stdio.h>
#include <errno.h>
#include <inttypes.h>
#include <math.h>
#include <fpstatus.h>
int main(int argc, char** argv)
{
double a, b;
a = 0.5;
b = logb(a);
printf("logb(%f) = %f (%f = 2^%f) \n", a, b, a, b);
return(0);
}
produces the output:
logb(0.500000) = -1.000000 (0.500000 = 2^-1.000000)
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | No |
| Signal handler | No |
| Thread | Yes |