Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <math.h>
double log(double x);
float log(float x); /* C++ only */
long double log(long double x); /* C++ only */
float logf(float x);
long double logl(long double x);
Returns the computed value.
If x is negative, the function sets errno to EDOM and returns -HUGE_VAL. If x is 0.0, the function returns -HUGE_VAL and sets errno to ERANGE. If the correct value would cause an underflow, 0 is returned and the value ERANGE is stored in errno.
Special behavior for IEEE: If x greater than 0, the function returns the natural logarithm (base e) of x.
⁄* CELEBL08
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);
}
The natural logarithm of 1000.000000 is 6.907755