Java.lang.StrictMath.log1p() Method

Advertisements


Description

The java.lang.StrictMath.log1p() method returns the natural logarithm of the sum of the argument and 1. For small values x, the result of log1p(x) is much closer to the true result of ln(1 + x) than the floating-point evaluation of log(1.0+x).It include some cases:

  • If the argument is NaN or less than -1, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is negative one, then the result is negative infinity.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Declaration

Following is the declaration for java.lang.StrictMath.log1p() method

public static double log1p(double x)

Parameters

  • x -- This is the value.

Return Value

This method returns the value ln(x + 1), the natural log of x + 1.

Exception

  • NA

Example

The following example shows the usage of java.lang.StrictMath.log1p() method.

package com.tutorialspoint;

import java.lang.*;

public class StrictMathDemo {

  public static void main(String[] args) {
  
    double d1 = 90 , d2 = 0.0 , d3 = (1.0/0.0);

    // returns the natural logarithm of the sum of the argument and 1
    double log1pValue = StrictMath.log1p(d1); 
    System.out.println("Logarithm value of double (d1 + 1) with base 10 :
    " + log1pValue);

    log1pValue = StrictMath.log1p(d2); 
    System.out.println("Logarithm value of double (d2 + 1) with base 10 :
    " + log1pValue);

    log1pValue = StrictMath.log1p(d3); 
    System.out.println("Logarithm value of double (d3 + 1) with base 10 :
    " + log1pValue);
  }
}

Let us compile and run the above program, this will produce the following result:

Logarithm value of double (d1+1) with base 10 : 4.51085950651685
Logarithm value of double (d2+1) with base 10 : 0.0
Logarithm value of double (d3+1) with base 10 : Infinity



Advertisements
Advertisements