log2 - C math.h

C examples for math.h:log2

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Returns the binary (base-2) logarithm of x.

Prototype

long double log2l (long double x);
long double log2 (long double x);
     double log2  (double x);
      float log2f (float x);
     double log2 (double x);
      float log2 (float x);
     double log2 (T x);           

Parameters

Parameter Description
x Value whose logarithm is calculated. If the argument is negative, a domain error occurs.

Return Value

The binary logarithm of x: log x base 2.

Example

Demo Code


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

int main ()/*from  w  w w . ja  v  a  2 s.  c  o m*/
{
  double param = 1024.0;
  
  double result = log2 (param);
  
  printf ("log2 (%f) = %f.\n", param, result );
  
  return 0;
}

Related Tutorials