Rate This Document
Findability
Accuracy
Completeness
Readability

logb

Compute the exponent of x and return the value in floating-point format.

Interface Definition

C interface:

float logbf(float x);

double logb(double x);

long double logbl(long double x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For logbf, x is of single-precision floating-point type.
  • For logb, x is of double-precision floating-point type.
  • For logbl, x is of long double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • The exponent of x is returned. The value range of single-precision y is [-150, 127] and that of double-precision y is [-1074, 1024].
  • If input x is ±∞, the return value is +∞.
  • If input x is ±0, the return value is -∞.
  • If input x is NaN, the return value is NaN.

Dependency

C: "km.h"

Example

C interface:
    // typical usage
    double x1 = 0.0, x2 = -0.0, x3 = 0x1p-1074, x4 = 0x1p1024;
    float x5 = 0x1p-149f;
    // special handing
    double a = INFINITY, b = -INFINITY, c = NAN;
    // print result
    printf("logb(0.0) = %.15f\n", logb(x1));
    printf("logb(-0.0) = %.15f\n", logb(x2));
    printf("logb(0x1p-1074) = %.15f\n", logb(x3));
    printf("logb(0x1p1024) = %.15f\n", logb(x4));
    printf("logbf(0x1p-150) = %.15f\n", logbf(x5));
    printf("logb(INFINITY) = %.15f\n", logb(a));
    printf("logb(-INFINITY) = %.15f\n", logb(b));
    printf("logb(NAN) = %.15f\n", logb(c));
    /* 
     * logb(0.0) = -inf
     * logb(-0.0) = -inf
     * logb(0x1p-1074) = -1074.000000000000000
     * logb(0x1p1024) = inf
     * logbf(0x1p-150) = -149.000000000000000
     * logb(INFINITY) = inf
     * logb(-INFINITY) = inf
     * logb(NAN) = nan
     * 
     * */