Java - StrictMath log1p(double) 方法



描述

Java StrictMath log1p(double x) 方法返回引數加 1 的自然對數。請注意,對於小的 x 值,log1p(x) 的結果比浮點數計算 log(1.0+x) 的結果更接近 ln(1 + x) 的真實結果。特殊情況:

  • 如果引數是 NaN 或小於 -1,則結果為 NaN。

  • 如果引數是正無窮大,則結果是正無窮大。

  • 如果引數是負一,則結果是負無窮大。

  • 如果引數是零,則結果是與引數符號相同的零。

宣告

以下是 java.lang.StrictMath.log1p() 方法的宣告

public static double log1p(double x)

引數

x − 一個值

返回值

此方法返回 ln(x + 1) 的值,即 x + 1 的自然對數

異常

獲取正雙精度值的 Log1p 示例

以下示例顯示了 StrictMath log1p() 方法的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = 10.7;

      // print the log1p of the number
      System.out.println("StrictMath.log1p(" + x + ")=" + StrictMath.log1p(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

StrictMath.log1p(10.7)=2.4595888418037104

獲取零雙精度值的 Log1p 示例

以下示例顯示了 StrictMath log1p() 方法對零值的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = 0.0;

      // print the log1p of the number
      System.out.println("StrictMath.log1p(" + x + ")=" + StrictMath.log1p(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

StrictMath.log1p(0.0)=0.0

獲取負雙精度值的 Log1p 示例

以下示例顯示了 StrictMath log1p() 方法對負數的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = -10.7;

      // print the log1p of the number
      System.out.println("StrictMath.log1p(" + x + ")=" + StrictMath.log1p(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

StrictMath.log1p(-10.7)=NaN
java_lang_strictmath.htm
廣告