gpt4 book ai didi

java - Math.hypo 函数

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:53:18 24 4
gpt4 key购买 nike

<分区>

为什么数学运算 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));
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com