java.lang.math,java.lang.math和java.lang.strictmash有什么区别?

Math.pow

public static double pow(double a, double b) {

return StrictMath.pow(a, b); // default impl. delegates to StrictMath

}

StrictMath.pow

Math.pow()

StrictMath.pow()

//Strict.java, testing StrictMath.pow against Math.pow

import java.util.Random;

public class Strict {

static double testIt(double x, double y) {

return Math.pow(x, y);

}

public static void main(String[] args) throws Exception{

final double[] vs = new double[100];

final double[] xs = new double[100];

final double[] ys = new double[100];

final Random random = new Random();

// compute StrictMath.pow results;

for (int i = 0; i<100; i++) {

xs[i] = random.nextDouble();

ys[i] = random.nextDouble();

vs[i] = StrictMath.pow(xs[i], ys[i]);

}

boolean printed_compiled = false;

boolean ever_diff = false;

long len = 1000000;

long start;

long elapsed;

while (true) {

start = System.currentTimeMillis();

double blackhole = 0;

for (int i = 0; i < len; i++) {

int idx = i % 100;

double res = testIt(xs[idx], ys[idx]);

if (i >= 0 && i<100) {

//presumably interpreted

if (vs[idx] != res && (!Double.isNaN(res) || !Double.isNaN(vs[idx]))) {

System.out.println(idx + ":\tInterpreted:" + xs[idx] + "^" + ys[idx] + "=" + res);

System.out.println(idx + ":\tStrict pow : " + xs[idx] + "^" + ys[idx] + "=" + vs[idx] + "\n");

}

}

if (i >= 250000 && i<250100 && !printed_compiled) {

//presumably compiled at this time

if (vs[idx] != res && (!Double.isNaN(res) || !Double.isNaN(vs[idx]))) {

System.out.println(idx + ":\tcompiled :" + xs[idx] + "^" + ys[idx] + "=" + res);

System.out.println(idx + ":\tStrict pow :" + xs[idx] + "^" + ys[idx] + "=" + vs[idx] + "\n");

ever_diff = true;

}

}

}

elapsed = System.currentTimeMillis() - start;

System.out.println(elapsed + " ms ");

if (!printed_compiled && ever_diff) {

printed_compiled = true;

return;

}

}

}

}

10: Interpreted:0.1845936372497491^0.01608930867480518=0.9731817015518033

10: Strict pow : 0.1845936372497491^0.01608930867480518=0.9731817015518032

41: Interpreted:0.7281259501809544^0.9414406865385655=0.7417808233050295

41: Strict pow : 0.7281259501809544^0.9414406865385655=0.7417808233050294

49: Interpreted:0.0727813262968815^0.09866028976654662=0.7721942440239148

49: Strict pow : 0.0727813262968815^0.09866028976654662=0.7721942440239149

70: Interpreted:0.6574309575966407^0.759887845481148=0.7270872740201638

70: Strict pow : 0.6574309575966407^0.759887845481148=0.7270872740201637

82: Interpreted:0.08662340816125613^0.4216580281197062=0.3564883826345057

82: Strict pow : 0.08662340816125613^0.4216580281197062=0.3564883826345058

92: Interpreted:0.20224488115245098^0.7158182878844233=0.31851834311978916

92: Strict pow : 0.20224488115245098^0.7158182878844233=0.3185183431197892

10: compiled :0.1845936372497491^0.01608930867480518=0.9731817015518033

10: Strict pow :0.1845936372497491^0.01608930867480518=0.9731817015518032

41: compiled :0.7281259501809544^0.9414406865385655=0.7417808233050295

41: Strict pow :0.7281259501809544^0.9414406865385655=0.7417808233050294

49: compiled :0.0727813262968815^0.09866028976654662=0.7721942440239148

49: Strict pow :0.0727813262968815^0.09866028976654662=0.7721942440239149

70: compiled :0.6574309575966407^0.759887845481148=0.7270872740201638

70: Strict pow :0.6574309575966407^0.759887845481148=0.7270872740201637

82: compiled :0.08662340816125613^0.4216580281197062=0.3564883826345057

82: Strict pow :0.08662340816125613^0.4216580281197062=0.3564883826345058

92: compiled :0.20224488115245098^0.7158182878844233=0.31851834311978916

92: Strict pow :0.20224488115245098^0.7158182878844233=0.3185183431197892

290 ms

Random

Math

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值