Format
#include <math.h> double log(double x);
Language Level: ANSI, POSIX, XPG4
log calculates the natural logarithm (base e) of x.
Return Value
log returns the computed value. If x is
negative, log sets errno to EDOM and may return the value
-HUGE_VAL. If x is zero, log returns the value -HUGE_VAL, and may
set errno to ERANGE.
Example
This example calculates the natural logarithm of 1000.0.
#include <math.h> #include <stdio.h>
int main(void)
{
double x = 1000.0,y;
y = log(x);
printf("The natural logarithm of %lf is %lf\n", x, y);
return 0;
/******************************************************
The output should be:
The natural logarithm of 1000.000000 is 6.907755 ******************************************************/ }
![]()
exp -- Calculate Exponential Function
log10 -- Calculate Base 10 Logarithm
pow -- Compute Power
<math.h>