1 function valuesAreClose(a
, b
) {
2 return Math
.abs(a
/ b
) - 1 < 1e-10;
5 // Small exponent values are handled through a simpler inline loop. Test that it is not observable.
6 function mathPowDoubleDoubleTestExponentFifty(x
, y
) {
9 noInline(mathPowDoubleDoubleTestExponentFifty
);
11 function mathPowDoubleIntTestExponentFifty(x
, y
) {
14 noInline(mathPowDoubleIntTestExponentFifty
);
15 function testExponentFifty(x
, y
, expected
) {
16 for (var i
= 0; i
< 10000; ++i
) {
17 var result
= mathPowDoubleDoubleTestExponentFifty(x
, y
);
18 if (!valuesAreClose(result
, expected
))
19 throw "Error: bad result, Math.pow(" + x
+ ", " + y
+ ") = " + result
+ " expected value close to " + expected
;
22 for (var i
= 0; i
< 10000; ++i
) {
23 var result
= mathPowDoubleIntTestExponentFifty(x
, integerY
);
24 if (!valuesAreClose(result
, expected
))
25 throw "Error: bad result, Math.pow(" + x
+ ", " + integerY
+ ") = " + result
+ " expected value close to " + expected
;
28 noInline(testExponentFifty
);
29 testExponentFifty(53.70901164133102, 50.0, 3.179494118120144e+86);
30 testExponentFifty(53.70901164133102, -10.0, 5.006432842621192e-18);
32 function mathPowDoubleDoubleTestExponentTenThousands(x
, y
) {
35 noInline(mathPowDoubleDoubleTestExponentTenThousands
);
37 function mathPowDoubleIntTestExponentTenThousands(x
, y
) {
40 noInline(mathPowDoubleIntTestExponentTenThousands
);
41 function testExponentTenThousands(x
, y
, expected
) {
42 for (var i
= 0; i
< 10000; ++i
) {
43 var result
= mathPowDoubleDoubleTestExponentTenThousands(x
, y
);
44 if (!valuesAreClose(result
, expected
))
45 throw "Error: bad result, Math.pow(" + x
+ ", " + y
+ ") = " + result
+ " expected value close to " + expected
;
48 for (var i
= 0; i
< 10000; ++i
) {
49 var result
= mathPowDoubleIntTestExponentTenThousands(x
, integerY
);
50 if (!valuesAreClose(result
, expected
))
51 throw "Error: bad result, Math.pow(" + x
+ ", " + integerY
+ ") = " + result
+ " expected value close to " + expected
;
54 noInline(testExponentTenThousands
);
55 testExponentTenThousands(1.001, 10000.0, 21916.681339048373);
56 testExponentTenThousands(1.001, -1.0, 0.9990009990009991);