# log1p() in C++

C++ProgrammingServer Side Programming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

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);

Here,

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

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

## Example

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;
}

## Output

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