Java Math log1p() Method

The log1p() method of Math class returns the natural logarithmic sum for the specified double argument and 1. Its value is much closer to result of ln(1 + x).

Syntax:

public static double log1p (double a)

Parameters:

The parameter ‘a’ represents a double value.

Return Value:

The log1p() method returns the natural log of x +1.

Special cases of the log1p() method are as follows:

  • It returns NaN, if the argument is NaN or less than -1.
  • It returns positive infinity, if the argument passed is positive infinite.
  • It returns negative infinity, if the argument passed is negative one.
  • It returns zero with the same sign as the argument, if the argument passed is equal to zero.

Example 1:

Output:

Example 2:

Output:

Example 3:

Output:

Example 4:

Output:

Example 5:

Output:

Example 6:

Output: