log1p() in C++

C++ProgrammingServer Side Programming

The function log1p() is used to calculate the natural logarithm (base e logarithm) of (a+1) where a is any number. It returns the value of natural logarithm of (a+1). It returns Not a number(Nan) when we pass a value which is less than -1.

Here is the mathematical expression of log1p(),

log1p(a) = base-e log(a+1)

Here is the syntax of log1p() in C++ language,

float log1p(float variable_name);


  • variable_name  − Any name given to the variable whose logarithmic value is calculated.

Here is an example of log1p() in C++ language,


 Live Demo

#include <iostream>
#include <cmath>
using namespace std;

int main() {
   int x = 10;
   float y = 28.88;

   cout << "The log value of x : " << log1p(x);
   cout << "\nThe log value of y : " << log1p(y);

   return 0;


Here is the output

The log value of x : 2.3979
The log value of y : 3.39719
Updated on 25-Jun-2020 10:11:47