Math.LN10 10的自然對數
Math.LOG2E 以2爲底E的對數
Math.LOG10E 以10爲底E的對數
Math.log(x) 返回x的對數(以e爲準)
例如
求某數的對數 以2爲準
public class Test {
public static void main(String[] args) {
// 1 2 4 8 16 32
System.out.println(log(Double.valueOf("4"),Double.valueOf("2")));
}
static public double log(double x, double y) {
return Math.log(x) / Math.log(y);
}
}
結果爲:2