Java.lang.StrictMath.log()是StrictMath類的內置方法,用於計算給定雙精度值的自然對數,即以e為底的對數。它產生三個特殊結果:
- 當參數為正無窮大時,它將返回正無窮大。
- 當參數為NaN或小於零時,它將返回NaN。
- 當參數為正零或負零時,結果為負無窮大。
用法:
public static double log(double num)
參數:該方法接受一個雙精度類型的參數num,其對數值將被找到。
返回值:該方法返回num的自然對數值。
例子:
Input: num = 5.0 Output: 1.6094379124341003 Input: num = 10.0 Output: 2.302585092994046
以下示例程序旨在說明Java.lang.StrictMath.log()方法:
示例1:
// Java praogram to illustrate the
// Java.lang.StrictMath.log() Method
import java.lang.*;
public class Geeks {
public static void main(String[] args) {
double num1 = 10 , num2 = 25.2 ;
// It returns natural logarithm(base e)
double log_Value = StrictMath.log(num1);
System.out.print("Log value of " + num1 + " = " );
System.out.println(log_Value);
log_Value = StrictMath.log(num2);
System.out.print("Log value of " + num2 + " = " );
System.out.println(log_Value);
}
}
輸出:
Log value of 10.0 = 2.302585092994046 Log value of 25.2 = 3.2268439945173775
示例2:
// Java praogram to illustrate the
// Java.lang.StrictMath.log() Method
import java.lang.*;
public class Geeks {
public static void main(String[] args) {
double num1 = 0 , num2 = (1.0/0.0) , num3 = 1;
// It returns natural logarithm(base e)
double log_Value = StrictMath.log(num1);
System.out.print("Log value of " + num1 + " = " );
System.out.println(log_Value);
log_Value = StrictMath.log(num2);
System.out.print("Log value of " + num2 + " = " );
System.out.println(log_Value);
log_Value = StrictMath.log(num3);
System.out.print("Log value of " + num3 + " = " );
System.out.println(log_Value);
}
}
輸出:
Log value of 0.0 = -Infinity Log value of Infinity = Infinity Log value of 1.0 = 0.0
相關用法
- Java StrictMath pow()用法及代碼示例
- Java StrictMath exp()用法及代碼示例
- Java StrictMath tan()用法及代碼示例
- Java StrictMath sin()用法及代碼示例
- Java StrictMath min()用法及代碼示例
- Java StrictMath signum()用法及代碼示例
- Java StrictMath nextUp()用法及代碼示例
- Java StrictMath max()用法及代碼示例
- Java StrictMath getExponent()用法及代碼示例
- Java StrictMath scalb()用法及代碼示例
- Java StrictMath cbrt()用法及代碼示例
- Java StrictMath cos()用法及代碼示例
- Java StrictMath random()用法及代碼示例
- Java StrictMath floor()用法及代碼示例
- Java StrictMath cosh()用法及代碼示例
注:本文由純淨天空篩選整理自ankita_chowrasia大神的英文原創作品 StrictMath log() Method In Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。