Java.lang.Math.log() 方法
描述
java.lang.Math.log(double a) 返回双精度值的自然对数(以 e 为底)。 特殊情况:
如果参数为 NaN 或小于零,则结果为 NaN。
如果参数为正无穷大,则结果为正无穷大。
如果参数为正零或负零,则结果为负无穷大。
声明
以下是 java.lang.Math.log() 方法的声明。
public static double log(double a)
参数
a − 一个值
返回值
此方法返回 ln a 的值,即 a 的自然对数。
异常
NA
示例
下面的例子展示了 lang.Math.log() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class MathDemo {
public static void main(String[] args) {
// get two double numbers
double x = 60984.1;
double y = -497.99;
// get the natural logarithm for x
System.out.println("Math.log(" + x + ")=" + Math.log(x));
// get the natural logarithm for y
System.out.println("Math.log(" + y + ")=" + Math.log(y));
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Math.log(60984.1)=11.018368453441132 Math.log(-497.99)=NaN

