作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
<分区>
为什么数学运算 Math.sqrt(x*x+y*y) 比 Math.hypo(x,y) 快得多?
public class Teste {
public static void main(String[] args) {
long ta = System.currentTimeMillis();
for( double x=0,y=0; x<5000000; x++,y+=2 ){
double d = Math.sqrt(x*x+y*y);
}
long tb = System.currentTimeMillis();
System.err.println((tb-ta));
ta = System.currentTimeMillis();
for( double x=0,y=0; x<5000000; x++,y+=2 ){
double d = Math.hypot(x,y);
}
tb = System.currentTimeMillis();
System.err.println((tb-ta));
}
}
这个问题在这里已经有了答案: Why hypot() function is so slow? (5 个答案) 关闭 9 年前。 为什么数学运算 Math.sqrt(x*x+y*y) 比 Math.
我是一名优秀的程序员,十分优秀!