logb Function

Calculates the signed exponent of a double precision floating-point value.

Include

<math.h>

Prototype

double logb(double x);

Argument

x
any positive value for which to return the exponent

Return Value

Returns the exponent of x as a signed floating-point value. The argument is treated as being normalized if it is a subnormal floating-point value.

Remarks

A domain error might occur if x is 0.

Example

#include <math.h>
#include <stdio.h>
#include <errno.h>

int main(void)
{
  double x, y;

  errno = 0;
  x = 13.45;
  y = logb(x);
  if (errno)
    perror("Error");
  printf("The exponent of %f is %f\n",
          x, y);

  errno = 0;
  x = 0.0;
  y = logb(x);
  if (errno)
    perror("Error");
  printf("The exponent of %f is %f\n",
          x, y);

  errno = 0;
  x = -2.0;
  y = logb(x);
  if (errno)
    perror("Error");
  printf("The exponent of %f is %f\n",
          x, y);
}

Example Output

The exponent of 13.450000 is 3.000000
The exponent of 0.000000 is -inf
The exponent of -2.000000 is 1.000000