Java教程

Java Math log10()

Java Math log10()

Java Math log10() 方法计算指定值的以 10 为底的对数并返回。
log10() 方法的语法是:
Math.log10(double x)
这里, log10() 是一个静态方法。因此,我们直接使用类名 Math 调用该方法。

log10() 参数

x-要计算其对数的值

log10() 返回值

返回以 10 为底的 x 的对数 如果 x 是 NaN 或小于零,则返回 NaN 如果 x 是正无穷大,则返回正无穷大 如果 x 为零,则返回负无穷大
注意: log10(10n) = n 的值,其中 n 为整数。

示例: Java Math.log10()

class Main {
  public static void main(String[] args) {
    // compute log10() for double value
    System.out.println(Math.log10(9.0));       // 0.9542425094393249
    // compute log10() for zero
    System.out.println(Math.log10(0.0));       //-Infinity
    // compute log10() for NaN
    double nanValue = Math.sqrt(-5.0);
    System.out.println(Math.log10(nanValue));  // NaN
    // compute log10() for infinity
    double infinity = Double.POSITIVE_INFINITY;
    System.out.println(Math.log10(infinity));  // Infinity
    // compute log10() for negative numbers
    System.out.println(Math.log(-9.0));      // NaN
    //compute log10() for 103
    System.out.println(Math.log10(Math.pow(10, 3)));  // 3.0
  }
}
在上面的例子中,注意表达式,
Math.log10(Math.pow(10, 3))
这里, Math.pow(10, 3) 返回 103。要了解更多信息,请访问 Java Math.pow()。

推荐教程

Java Math.log() Java Math.log1p()
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4