logarithm functions

You're viewing an older version of this page (#3333). View the current version.

View versions (5)

NAME

log, log2, log10, log1p

INTERFACE

#include <math.h>

double log ( double x ) long logl ( long double x ) float logf ( float x ) double log2 ( double x ) long log2l ( long double x ) float log2f ( float x ) double log10 ( double x ) long log10l ( long double x ) float log10f ( float x ) double log1p ( double x ) long log1pl ( long double x ) float log1pf ( float x )

DESCRIPTION

The log function computes the value of the natural logarithm of argument x.
The log2 function computes the value of the logarithm of argument x to base 2.
The log10 function computes the value of the logarithm of argument x to base 10.
The log1p function computes the value of log(1+x) accurately even for very small values of x.

Example 1

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

  int main(void)
  {
    double val = 1.0,s;

    do {
      printf("The log , log10 , log2 of %f are %f %f %f\n", val, log(val) , log10(val) , log2(val));           
      val++;
    } while (val<5.0);
    
    return 0;
  }

output

The log , log10 , log2 of  1.000000 are 0.000000  0.000000  0.000000	
The log , log10 , log2 of  2.000000 are 0.693147  0.301030  1.000000
The log , log10 , log2 of  3.000000 are 1.098612  0.477121  1.584963
The log , log10 , log2 of  4.000000 are 1.386294  0.602060  2.000000

SPECIAL VALUES

log ( &plusmn;0 ), log2 ( &plusmn;0 ), and log10 ( &plusmn;0 ) return -&infin; and raise the divide-by-zero floating-point exception.
log ( 1 ), log2 ( 1 ), and log10 ( 1 ) return +0.
log ( x ), log2 (x ), and log10 ( x ) return a NaN and raise the invalid floating-point exception for x < 0.
log ( +&infin; ), log2 ( +&infin;), and log10 ( +&infin; ) return +&infin;.
log1p ( &plusmn;0 ) returns &plusmn;0.
log1p ( -1 ) returns -&infin; and raises the divide-by-zero floating-point exception.
log1p ( x ) returns a NaN and raises the invalid floating-point exception for x < -1.
log1p ( +&infin; ) returns +&infin;.

SEE ALSO

exp (3) , reference:exp2 (3) , reference:expm1 (3) , pow (3)

STANDARDS

The log , log2 , log10 , and log1p functions conform to ISO/IEC 9899:1999(E).