Math的属性之对数

来源:互联网 发布:何凯文和田静语法知乎 编辑:程序博客网 时间:2024/05/29 03:42

Math的属性之对数

    博客分类: 
  • java
Math的属性对数Math
Math.LN2 2的自然对数 
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