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.

Return Value

The natural logarithm of (1+x).
If x is less than -1, it causes a domain error.
If x is -1, it may cause a pole error (depending on the library implementation).

If a domain error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to EDOM.
- And math_errhandling has MATH_ERREXCEPT set: FE_INVALID is raised.

If a pole error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to ERANGE.
- And math_errhandling has MATH_ERREXCEPT set: FE_DIVBYZERO is raised.

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