Java - StrictMath log(double) 方法



描述

Java StrictMath log(double a) 返回雙精度值的自然對數(以 e 為底)。特殊情況

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

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

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

宣告

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

public static double log(double a)

引數

a − 一個值

返回值

此方法返回 ln a 值,即 a 的自然對數。

異常

獲取正雙精度值的對數示例

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

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = 10.7;

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

輸出

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

StrictMath.log(10.7)=2.3702437414678603

獲取零雙精度值的對數示例

以下示例顯示了 StrictMath log() 方法在零值上的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = 0.0;

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

輸出

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

StrictMath.log(0.0)=-Infinity

獲取負雙精度值的對數示例

以下示例顯示了 StrictMath log() 方法在負數上的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

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

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

輸出

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

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