]> git.saurik.com Git - apple/javascriptcore.git/blame - 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
CommitLineData
ed1e77d3
A
1function 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.
6function mathPowDoubleDoubleTestExponentFifty(x, y) {
7 return Math.pow(x, y)
8}
9noInline(mathPowDoubleDoubleTestExponentFifty);
10
11function mathPowDoubleIntTestExponentFifty(x, y) {
12 return Math.pow(x, y)
13}
14noInline(mathPowDoubleIntTestExponentFifty);
15function 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}
28noInline(testExponentFifty);
29testExponentFifty(53.70901164133102, 50.0, 3.179494118120144e+86);
30testExponentFifty(53.70901164133102, -10.0, 5.006432842621192e-18);
31
32function mathPowDoubleDoubleTestExponentTenThousands(x, y) {
33 return Math.pow(x, y)
34}
35noInline(mathPowDoubleDoubleTestExponentTenThousands);
36
37function mathPowDoubleIntTestExponentTenThousands(x, y) {
38 return Math.pow(x, y)
39}
40noInline(mathPowDoubleIntTestExponentTenThousands);
41function 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}
54noInline(testExponentTenThousands);
55testExponentTenThousands(1.001, 10000.0, 21916.681339048373);
56testExponentTenThousands(1.001, -1.0, 0.9990009990009991);