function
<cmath> <ctgmath>
log1p
double log1p (double x);
float log1pf (float x);
long double log1pl (long double x);
double log1p (double x);
float log1p (float x);
long double log1p (long double x);
double log1p (T x); // additional overloads for integral types
Compute logarithm plus one
Returns the natural logarithm of one plus x.
For small magnitude values of x, logp1 may be more accurate than log(1+x)
.
Header
<tgmath.h> provides a type-generic macro version of this function.
Additional overloads are provided in this header (
<cmath>
) for the
integral types: These overloads effectively cast
x to a
double
before calculations (defined for
T being any
integral type).
Parameters
- x
- Value whose logarithm is calculated.
If the argument is less than -1
, a domain error occurs.
Example
1 2 3 4 5 6 7 8 9 10 11 12
|
/* log1p example */
#include <stdio.h> /* printf */
#include <math.h> /* log1p */
int main ()
{
double param, result;
param = 1.0;
result = log1p (param);
printf ("log1p (%f) = %f.\n", param, result );
return 0;
}
|
Output:
log1p (1.000000) = 0.693147
|
See also
- exp
- Compute exponential function (function
)
- log1p
- Compute logarithm plus one (function
)
- pow
- Raise to power (function
)