Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

log, logf, logl - Natural logarithm

&pagelevel(4)&pagelevel

Definition

#include <math.h>

double log(double x);
float logf(double x); (C11)
long double logl(long double x); (C11)

These functions calculate the natural logarithm of the positive floating-point number x to the base e.

Return val.

ln(x)

for positive x.


-HUGE_VAL
-HUGE_VALF
-HUGE_VALL

depending on the function type,
if x is less than or equal to 0. In addition, errno is set to EDOM (domain error)

or
if x is equal to 0. In addition, errno is set to ERANGE.

Example

#include <math.h>
#include <stdio.h>
int main(void)
{
  double x;
  printf("Example of log(x): Please enter x\n");
  if(scanf("%lf", &x) == 1)
  printf("x = %g log(x) = %g\n", x, log(x));
  return 0;
}

See also

log2, log10, exp, exp2