×

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:

public class JavaMathLog1pExample1 {
    public static void main(String[] args) {
        double a = 10;
        // returns the natural log of x +1
        System.out.println("Logrithm 1p value for "+a +" : "+Math.log1p(a));
    }
}

Output:

Logrithm 1p value for 10.0 : 2.3978952727983707

Example 2:

public class JavaMathLog1pExample2 {
    public static void main(String[] args) {
        double a = -100;
        //returns NaN, if the argument is NaN or less than -1
        System.out.println("Logrithm 1p value for "+a +" : "+Math.log1p(a));
    }
}

Output:

Logrithm 1p value for -100.0 : NaN

Example 3:

public class JavaMathLog1pExample3 {
    public static void main(String[] args) {
        double a = 10/0.0d;
        // positive infinity, if the argument passed is positive infinite
        System.out.println("Logrithm 1p value for "+a +" : "+Math.log1p(a));
    }
}

Output:

Logrithm 1p value for Infinity : Infinity

Example 4:

public class JavaMathLog1pExample4 {
    public static void main(String[] args) {
        double a = -1;
        // returns negative infinity, if the argument passed is negative one
        System.out.println("Logrithm 1p value for "+a +" : "+Math.log1p(a));
    }
}

Output:

Logrithm 1p value for -1.0 : -Infinity

Example 5:

public class JavaMathLog1pExample5 {
    public static void main(String[] args) {
        double a = -0;
        //returns zero with the same sign as the argument, if the argument passed is equal to zero
        System.out.println("Logrithm 1p value for "+a +" : "+Math.log1p(a));
    }
}

Output:

Logrithm 1p value for 0.0 : 0.0

Example 6:

public class JavaMathLog1pExample6 {
    public static void main(String[] args) {
        double a = -100;
        // returns NaN, if the argument passed is NaN or less than -1
        System.out.println("Logrithm 1p value for "+a +" : "+Math.log1p(a));
    }
}

Output:

Logrithm 1p value for -100.0 : NaN

Related Topics

Java Clone Array

We frequently need to copy an array to back up its original components. We have a few unique numbers and strings, including Armstrong numbers, palindrome numbers, and palindrome strings. To...

4 minutes read.

Java Strictfp Keyword

Strictfp is used to impose limits on floating-point calculation. It ensures that we will get the same result on every platform while performing an operation with the floating-point variable. The floating-point calculation is platform-dependent due...

1 minute read.

How to Set Java_home in Linux

To set the Java_home in Linux, we must follow several steps to make us understand it easily.  Java follows the principle called WORA (write once run anywhere). We know that java...

3 minutes read.

Association in Java

In Java, association refers to the link between two classes established by their objects. One-to-one, one-to-many, and many-to-many connections are managed via association. The Association defines the multiplicity between objects...

5 minutes read.

Java Lock

A lock is indeed a threaded synchronization technique similar to Java's synchronized blocks, however, locking can be more complex. It's not like we can completely get rid of the synchronized...

5 minutes read.

Interface Program in Java

Interface Program in Java In the previous topic, we discussed that abstraction is possible through the interface and abstract class. An abstract class provides partial to 100% abstraction. 100 %abstraction in...

4 minutes read.

This Operator Using in Java

this keyword in Java has a wide range of applications. this reference variable in Programming language refers to the object of interest. This keyword is used in Java. this keyword is...

5 minutes read.

Java Generate UUID

What java Generate UUID? A 128-bit long value that is universally unique serves as the basis for the terms UUID (Universally Unique Identifier) and GUID (Globally Unique Identifier). Hexadecimal (octet) digits...

5 minutes read.

Java Technologies List

Introducing Java technology is not necessary. Everyone across the globe is still in awe of Java's incredible capabilities for developing mobile apps and websites. Of course, you can be persuaded...

8 minutes read.

Undo and Redo Operations in Java

Undo and redo operation are the most widely used operation while dealing with file. In this section, we will discuss how to implement undo and redo operation in Java. Undo Redo...

2 minutes read.

How to Convert String to double in Java

How to Convert String to double in java It is used if we have to perform mathematical operations on the string that contains a double number. When we get data from...

3 minutes read.

Java logger

Logging is a crucial Java feature that aids developers in identifying issues. The logging methodology is included with Java as the programming language. It offers the Logging API, which debuted...

7 minutes read.

Java String compareTo() Method

compareTo() method is used to compare the two specified Strings based on the alphabetical order(lexicographical order) of their characters.It returns positive number ,negative number or 0 Syntax: public int compareTo(String anotherString) Parameters: anotherString: the...

2 minutes read.

Program to Find Square Root of a Number Without sqrt Method in Java

The Java Math class sqrt () function can be used to determine the square root of a number. In this section, we'll write a Java program to find a number's...

3 minutes read.

Vector in Java

Java Vector Class The Vector class is a legacy class that implements a growable array of objects. The components that it contains can be accessed using an integer index. The size of...

26 minutes read.

Swastika Pattern in Java

This part teaches us how to create the Swastika Pattern in Java utilizing user-defined columns and rows as well as stars or other special characters.A Java pattern application that is...

2 minutes read.

Matrix Multiplication in Java

In Java, using the binary operator (*) we can perform matrix multiplication. A Matrix is a group of arrays. In the multiplication of matrices, the elements of each row are...

3 minutes read.

String to JSON in Java

Nowadays, receiving data in JSON String format rather than XML is quite frequent. Java does not transform JSON String to JSON Object when dealing with JSON String. However, using the...

3 minutes read.

Java program to determine whether all leaves are at same level

In this program, we must determine whether or not all of the binary tree's leaves are at the same level. If a node has no child nodes, it is said to...

3 minutes read.

Java time local date

Java: Java is one of the programming language which is object oriented. It consists of many features such as robust, simple, architecture neutral, dynamic, distributed, multi threaded, portable etc. The main feature...

3 minutes read.