C Standard Library

C <math.h> - log1p() Function



The C <math.h> log1p() function returns the natural logarithm of (1 + number), i.e., log(1+number).

Syntax

double log1p (double x);
float log1pf (float x);
long double log1pl (long double x);

Parameters

x Specify the number.

Return Value

Returns the natural logarithm of (1 + number), i.e., log(1+number).
If the x is less than -1, domain error occurs.

Example:

In the example below, log1p() function is used to calculate the log(1+number).

#include <stdio.h>
#include <math.h>
 
int main (){
  printf("%lf\n", log1p(0));
  printf("%lf\n", log1p(1));
  printf("%lf\n", log1p(2));
  return 0;
}

The output of the above code will be:

0.000000
0.693147
1.098612

❮ C <math.h> Library