目录

static double log(double a)

描述 (Description)

java.lang.Math.log(double a)返回double值的自然对数(基数e)。 特别案例:

  • 如果参数为NaN或小于零,则结果为NaN。

  • 如果参数是正无穷大,那么结果是正无穷大。

  • 如果参数为正零或负零,则结果为负无穷大。

声明 (Declaration)

以下是java.lang.Math.log()方法的声明

public static double log(double a)

参数 (Parameters)

a - 一个值

返回值 (Return Value)

此方法返回值ln a,a的自然对数。

异常 (Exception)

NA

例子 (Example)

以下示例显示了lang.Math.log()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018