java.lang.Math.log()方法返回双精度值的自然对数(以e为底)作为参数。有多种情况:
如果参数为NaN或小于零,则结果为NaN。
如果参数为正无穷大,则结果为正无穷大。
如果参数为正零或负零,则结果为负无穷大。
用法:
public static double log(double a)
参数:
a:User input
返回:
This method returns the value ln a.
例:展示java.lang.Math.log()方法的用法。
// Java program to demonstrate working
// of java.lang.Math.log() method
import java.lang.Math;
class Gfg {
// driver code
public static void main(String args[])
{
double a = -2.55;
double b = 1.0 / 0;
double c = 0, d = 145.256;
// negative integer as argument, output NAN
System.out.println(Math.log(a));
// positive infinity as argument, output Infinity
System.out.println(Math.log(b));
// positive zero as argument, output -Infinity
System.out.println(Math.log(c));
// positive double as argument
System.out.println(Math.log(d));
}
}
输出:
NaN
Infinity
-Infinity
4.978497702968366