# Java Math Class static double log1p(double d) with example

Java Math Class static double log1p(double d) method: Here, we are going to learn about the static double log1p(double d) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 04, 2019

## Math Class static double log1p(double d)

• This method is available in java.lang package.
• This method is used to return (the logarithm of the sum of the given argument and 1 like log(1+d)) in the method.
• This is a static method so it is accessible with the class name too.
• We need to remember one thing if we pass smaller values for the given argument so the final calculated result of log1p(d) is nearer to the exact result of ln(1+d) than the double floating-point calculation of log(1.0+d)
• The return type of this method is double, it returns the logarithm (1+d) of the given argument.
• In this method, we pass only one parameter as an argument of double type.
• This method does not throw any exception.

Syntax:

```    public static double log1p(double d){
}
```

Parameter(s): It accepts a double value, whose logarithm of the sum of the given argument and 1 like log(1+d)

Return value:

The return type of this method is double, it returns the logarithm (1+d) of the given argument.

Note:

• If we pass "NaN", it returns "NaN".
• If we pass value less than -1, it returns "NaN".
• If we pass a positive infinity, it returns the same value (positive infinity).
• If we pass a negative infinity, it returns the "NaN".
• If we pass zero (-0 or 0), it returns the same value.

### Java program to demonstrate example of log1p(double d) method

```// Java program to demonstrate the example of
// log1p(double d) method of Math Class.

public class Log1pMethod {
public static void main(String[] args) {
// Here we are declaring few variables
double d1 = 7.0 / 0.0;
double d2 = -7.0 / 0.0;
double d3 = 0.0;
double d4 = -0.0;
double d5 = 6054.2;

// displaying the values
System.out.println("d1 :" + d1);
System.out.println("d2 :" + d2);
System.out.println("d3 :" + d3);
System.out.println("d4 :" + d4);
System.out.println("d5 :" + d5);

// Here , we will get (Infinity) because we are passing
// parameter whose value is (Infinity)
System.out.println("Math.log1p(d1): " + Math.log1p(d1));

// Here , we will get (NaN) because we are passing
// parameter whose value is (-Infinity)
System.out.println("Math.log1p(d2): " + Math.log1p(d2));

// Here , we will get (0.0) because we are passing
// parameter whose value is (0.0)
System.out.println("Math.log1p(d3):" + Math.log1p(d3));

// Here , we will get (-0.0) because we are passing
// parameter whose value is (-0.0)
System.out.println("Math.log1p(d4):" + Math.log1p(d4));

// Here , we will get (log [1 + d5]) and we are
// passing parameter whose value is (6054.2)
System.out.println("Math.log1p(d5):" + Math.log1p(d5));
}
}
```

Output

```E:\Programs>javac Log1pMethod.java

E:\Programs>java Log1pMethod
d1 :Infinity
d2 :-Infinity
d3 :0.0
d4 :-0.0
d5 :6054.2
Math.log1p(d1): Infinity
Math.log1p(d2): NaN
Math.log1p(d3):0.0
Math.log1p(d4):-0.0
Math.log1p(d5):8.708672685994957
```