Java 帶示例的 log1p()


java.lang.Math.log1p(double x) 返回引數和 1 之和的自然對數。請注意,對於小值 x,log1p(x) 的結果比浮點評估 log(1.0+x) 的結果更接近 ln(1 + x) 的真實結果。特殊情況 −

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

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

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

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

示例

以下是一個在 Java 中實現 log1p() 方法的示例 −

import java.lang.*;
public class Example {
   public static void main(String[] args) {
      // get two double numbers
      double x = 23878.4;
      double y = 1000;
      // call log1p and print the result
      System.out.println("Math.log1p(" + x + ")=" + Math.log1p(x));
      // call log1p and print the result
   }
}

輸出

Math.log1p(23878.4)=10.080771441562744
Math.log1p(1000.0)=6.90875477931522

示例

讓我們看另一個示例 −

import java.lang.*;
public class Example {
   public static void main(String[] args) {
      // get two double numbers
      double x = -130.25;
      double y = 0;
      double z = -20;
      System.out.println("Math.log1p(" + x + ")=" + Math.log1p(x));
      System.out.println("Math.log1p(" + y + ")=" + Math.log1p(y));
      System.out.println("Math.log1p(" + y + ")=" + Math.log1p(z));
   }
}

輸出

Math.log1p(-130.25)=NaN
Math.log1p(0.0)=0.0
Math.log1p(0.0)=NaN

更新於: 24-9 月-2019

93 次瀏覽

開啟你的 事業

完成課程並獲得認證

現在開始
廣告
© . All rights reserved.