]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/math-pow-integer-exponent-fastpath.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / math-pow-integer-exponent-fastpath.js
1 function valuesAreClose(a, b) {
2 return Math.abs(a / b) - 1 < 1e-10;
3 }
4
5 // Small exponent values are handled through a simpler inline loop. Test that it is not observable.
6 function mathPowDoubleDoubleTestExponentFifty(x, y) {
7 return Math.pow(x, y)
8 }
9 noInline(mathPowDoubleDoubleTestExponentFifty);
10
11 function mathPowDoubleIntTestExponentFifty(x, y) {
12 return Math.pow(x, y)
13 }
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;
20 }
21 var integerY = y | 0;
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;
26 }
27 }
28 noInline(testExponentFifty);
29 testExponentFifty(53.70901164133102, 50.0, 3.179494118120144e+86);
30 testExponentFifty(53.70901164133102, -10.0, 5.006432842621192e-18);
31
32 function mathPowDoubleDoubleTestExponentTenThousands(x, y) {
33 return Math.pow(x, y)
34 }
35 noInline(mathPowDoubleDoubleTestExponentTenThousands);
36
37 function mathPowDoubleIntTestExponentTenThousands(x, y) {
38 return Math.pow(x, y)
39 }
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;
46 }
47 var integerY = y | 0;
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;
52 }
53 }
54 noInline(testExponentTenThousands);
55 testExponentTenThousands(1.001, 10000.0, 21916.681339048373);
56 testExponentTenThousands(1.001, -1.0, 0.9990009990009991);