# log1p() in C++

The log1p() function takes an argument x and returns the natural logarithm of the base-e logarithm of x+1. Here e is a mathematical constant with value equal to 2.71828.

Syntax:

```double log1p (double x);
float log1p (float x);
long double log1p (long double x);
```

Parameter:

• The log1p() function takes a single argument in the range [-1, ?].
• If we pass the value which is less than -1, log1p() returns Nan (Not a Number).
• Return:

• a positive number : if x > 0
• zero if x=0
• a negative number if -1 > x > 0
• -?(- infinity) if x=-1
• NaN if x<-1

Error and Exception:

1. It is mandatory to give both the arguments otherwise it will give error no matching function for call to ‘log1p()’.
2. If we pass the string as argument we will get errorbno matching function for call to ‘log1p(const char [n]).
3. It gives -inf if we pass -1.
4. It gives zero if we pass 0.

Examples:

```Input  : log1p(50.35)
Output :  3.93866
```
```Input  : log1p(143)
Output : 4.96981
```

# CODE 1

 `// CPP program to illustrate log1p() ` `#include ` `#include ` `using` `namespace` `std; ` ` `  `int` `main() ` `{ ` `    ``double` `x = 50.35, answer; ` ` `  `    ``// returns logarithm of 51.35 base e ` `    ``answer = log1p(x); ` `    ``cout << ``"log1p("` `<< x << ``") = "`  `         ``<< answer << endl; ` ` `  `    ``return` `0; ` `} `

Output:

```log1p(50.35) = 3.93866
```

# CODE 2

 `// CPP program to illustrate log1p() ` `#include ` `#include ` ` `  `using` `namespace` `std; ` ` `  `int` `main() ` `{ ` `    ``double` `answer; ` `    ``int` `x = 143; ` ` `  `    ``// returns logarithm of 144 base e ` `    ``answer = log1p(x); ` `    ``cout << ``"log1p("` `<< x << ``") = "`  `         ``<< answer << endl; ` ` `  `    ``return` `0; ` `} `

Output:

```log1p(143) = 4.96981
```

Practical usage:

• It is practically used to get logarithm value of given argument+1.

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.