function
<cmath> <ctgmath>
log
double log ( double x);
float logf ( float x);
long double logl (long double x);
double log ( double x);
float log ( float x);
long double log (long double x);
double log (double x);
float log (float x);
long double log (long double x);
double log (T x); // additional overloads for integral types
Compute natural logarithm
Returns the natural logarithm of x.
The natural logarithm is the base-e logarithm: the inverse of the natural exponential function (exp). For common (base-10) logarithms, see log10.
Header
<tgmath.h> provides a type-generic macro version of this function.
Parameters
- x
- Value whose logarithm is calculated.
If the argument is negative, a domain error occurs.
Return Value
Natural logarithm of x.
If x is negative, it causes a domain error.
If x is zero, it may cause a pole error (depending on the library implementation).
If a
domain error occurs, the global variable
errno is set to
EDOM.
If a
pole error occurs, the global variable
errno is set
ERANGE.
Example
1 2 3 4 5 6 7 8 9 10 11 12
|
/* log example */
#include <stdio.h> /* printf */
#include <math.h> /* log */
int main ()
{
double param, result;
param = 5.5;
result = log (param);
printf ("log(%f) = %f\n", param, result );
return 0;
}
|
Output:
See also
- log10
- Compute common logarithm (function
)
- exp
- Compute exponential function (function
)
- pow
- Raise to power (function
)