log2l Function

Calculates the base-2 logarithm of a long double-precision floating-point value.

Include

<math.h>

Prototype

long double log2l(long double x);

Argument

x
any long double-precision floating-point positive number

Return Value

Returns the base-2 logarithm of x. If x is +/-0, -infinity is returned. If x is < 0, NaN is returned .

Remarks

If x is less than 0, a domain error will occur and errno will be set to EDOM.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

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

int main(void)
{
  double x, y;

  errno = 0;
  x = 2.0;
  y = log2l(x);
  if(errno)
    perror("Error");
  printf("The base-2 logarithm of %Lf is %Lf\n", x, y);

  errno = 0;
  x = 0.0;
  y = log2l(x);
  if(errno)
    perror("Error");
  printf("The base-2 logarithm of %Lf is %Lf\n", x, y);

  errno = 0;
  x = -2.0;
  y = log2l(x);
  if(errno)
    perror("Error");
  printf("The base-2 logarithm of %Lf is %Lf\n", x, y);
}

Example Output

The base-2 logarithm of 2.000000 is 1.000000
The base-2 logarithm of 0.000000 is -inf
Error: domain error
The base-2 logarithm of -2.000000 is nan