Java log10() 示例
Java.lang.Math.log10()是Java数学库方法之一,用于返回基数 10
给定双精度值的对数值作为参数。有各种情况:
- 如果参数是正双精度值,Math.log10() 方法将返回给定的对数
值。 - 如果参数为NaN 或小于零,则 Math.log10() 方法将返回NaN 。
- 如果参数是正无穷大,Math.log10() 方法将返回结果为正无穷大。
- 如果参数为正或负零,Math.log10() 方法将返回结果为Negative
无穷大。句法 :
public static double log10(double a)
范围 :
a : User input
返回 :
This method returns the base 10 logarithm of a.
示例:显示Java.lang.Math.log10()方法的工作。
// Java program to demonstrate working // of java.lang.Math.log10() method import java.lang.Math; class Gfg { // driver code public static void main(String args[]) { double a = 1000; double b = 145.256; double c = -6.04; double d = 1.0 / 0; double e = 0; // A power of 10 as input System.out.println(Math.log10(a)); // positive double value as argument, // output double value System.out.println(Math.log10(b)); // negative integer as argument, // output NAN System.out.println(Math.log10(c)); // positive infinity as argument, // output Infinity System.out.println(Math.log10(d)); // positive zero as argument, // output -Infinity System.out.println(Math.log10(e)); } }
输出:3.0 2.1621340805671756 NaN Infinity -Infinity