Javatpoint Logo
Javatpoint Logo

C++ Math log1p()

The function computes the natural logarithm of a given number plus one.

Suppose a number is 'x':

Syntax

Note: The return_type can be float, double or long double.

Parameter

x: The value of which logarithm is to be calculated.

Return value

Parameter Return value
x>0 Positive
x=0 zero
0>x> -1 Negative
x= -1 -infinity
x<-1 Not a Number(nan)

Example 1

Let's see a simple example when the value of x is greater than zero.

Output:

Value of x is : 10
log1p(x) = 2.3979

In this example, log1p() function computes the logarithm value when x is greater than zero.

Example 2

Let's see a simple example when the value of x is zero

Output:

Value of x is : 0
log1p(x) = 0

In this example, log1p() function computes the logarithm value when the value of x is zero.

Example 3

Let's see a simple example when the value of x is less than zero.

Output:

Value of x is : -0.5
log1p(x) = -0.693147

In this example, log1p() function computes the logarithm value when the value of x is less than zero.

Example 4

Let's see the simple example when the value of x is -1.

Output:

Value of x is : -1
log1p(x) = -inf

In this example, log1p() function computes the logarithm value when the value of x is -1.

Example 5

Let's see the simple example when the value of x is less than -1.

Output:

Value of x is : -3
log1p(x) = -nan

In this example, log1p() function computes the logarithm value when the value of x is less than -1.


Next TopicC++ Math Functions





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA