log2(), log2f(), log2l() — Calculate the base-2 logarithm

Standards

Standards / Extensions C or C++ Dependencies

C99
Single UNIX Specification, Version 3
C++ TR1 C99

both z/OS® V1R5

Format

#define _ISOC99_SOURCE
#include <math.h>

double log2(double x);
float log2f(float x);
long double log2l(long double x);
C++ TR1 C99:
#define _TR1_C99
#include <math.h>

float log2(float x); 
long double log2(long double x);

General description

The log2 functions compute the base-2 logarithm of x.
Note: The following table shows the viable formats for these functions. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.
Function Hex IEEE
log2 X X
log2f X X
log2l X X

Returned value

The log2 functions return log2 x.

A domain error occurs if x is less than zero. A range error may occur if x is zero.

Special behavior for IEEE: If x is equal to 0, a pole error will occur and errno remains unchanged.

When environment variable _EDC_SUSV3 is set to 2, and if x is equal to 0, the function returns -HUGE_VAL and sets errno to ERANGE.

Related information