Home >>Java Math Methods >Java Math.log1() method

Java Math.log1() method

Java Math.log1() method

The Math.log1p() method in Java Math is used to return the sum of the arguments and the natural logarithm 1.

Syntax

public static double log1p(double x) 

Parameters

x= This parameter is used for a double value

Returns

It is used to returns the value ln(x + 1), the natural log of x + 1

  1. If the statement is Positive value this method returns a given value's natural logarithm.
  2. If the statement is -1 or less than -1, then -1 is returned by this method.
  3. This method returns Negative Infinity if the statement is -1.
  4. If Positive Infinity is the statement, then this method returns Positive Infinity.
  5. This method will return the Zero with the same sign as the argument if the argument is positive or negative Zero.

Java Math.log1() Method Example 1


public class MyClass
{  
    public static void main(String[] args)   
    {  
        double a = 12;  
        System.out.println(Math.log1p(a));  
    }  
}  

Output:
2.5649493574615367

Java Math.log1() Method Example 2


public class MyClass  
{  
    public static void main(String[] args)   
    {  
        double a = -3.14;  
        System.out.println(Math.log1p(a));  
    }  
}  

Output:
NaN