blob: d2a1de2295342f066a3db9d5bd0fc7c43e71f29a [file] [log] [blame]
benjamin@webkit.org88d9c892016-04-28 20:50:08 +00001// This test verify the results of Math.pow() do not change as we change optimization tier.
2
3function opaquePow(a, b)
4{
5 return Math.pow(a, b);
6}
7noInline(opaquePow);
8
9
10let caseStrings = [
11 "0",
12 "-0.",
13 "0.5",
14 "1",
15 "2",
16 "-0.5",
17 "-1",
18 "999",
19 "1000",
20 "1001",
21 "NaN",
22 "Infinity",
23 "-Infinity",
24 "Math.PI",
25 "Math.LN2",
26 "Math.LN10",
27 "Math.E",
28 "Math.LOG10E",
29 "Math.LOG2E",
30 "Math.SQRT2"
31];
32let cases = [];
33for (let caseString of caseStrings) {
34 cases.push(eval(caseString));
35}
36
37let expectedResults = [];
38let constantBaseFunctions = [];
39let constantExponentFunctions = [];
40for (let i = 0; i < cases.length; ++i) {
41 let base = cases[i];
42
43 expectedResults[i] = [];
44 for (let j = 0; j < cases.length; ++j) {
45 let exponent = cases[j];
46 expectedResults[i][j] = Math.pow(base, exponent);
47 }
48
49 eval("constantBaseFunctions[i] = function (exponent) { return Math.pow(" + caseStrings[i] + ", exponent); }");
50 eval("constantExponentFunctions[i] = function (base) { return Math.pow(base, " + caseStrings[i] + "); }");
51}
52
53function isIdentical(result, expected)
54{
55 if (expected === expected) {
56 if (result !== expected)
57 return false;
58 if (!expected && 1 / expected === -Infinity && 1 / result !== -Infinity)
59 return false;
60
61 return true;
62 }
63 return result !== result;
64}
65
66for (let tierUpLoopCounter = 0; tierUpLoopCounter < 1e3; ++tierUpLoopCounter) {
67 for (let i = 0; i < cases.length; ++i) {
68 let base = cases[i];
69 for (let j = 0; j < cases.length; ++j) {
70 let exponent = cases[j];
71 let expectedResult = expectedResults[i][j];
72 let result = opaquePow(base, exponent);
73 if (!isIdentical(result, expectedResult))
utatane.tea@gmail.combaef4072016-05-17 13:43:29 +000074 throw `Failed opaquePow with base = ${base} exponent = ${exponent} expected (${expectedResult}) got (${result})`;
benjamin@webkit.org88d9c892016-04-28 20:50:08 +000075
76 result = constantBaseFunctions[i](exponent);
77 if (!isIdentical(result, expectedResult))
utatane.tea@gmail.combaef4072016-05-17 13:43:29 +000078 throw `Failed constantBaseFunctions with base = ${base} exponent = ${exponent} expected (${expectedResult}) got (${result})`;
benjamin@webkit.org88d9c892016-04-28 20:50:08 +000079
80 result = constantExponentFunctions[j](base);
81 if (!isIdentical(result, expectedResult))
utatane.tea@gmail.combaef4072016-05-17 13:43:29 +000082 throw `Failed constantExponentFunctions with base = ${base} exponent = ${exponent} expected (${expectedResult}) got (${result})`;
benjamin@webkit.org88d9c892016-04-28 20:50:08 +000083 }
84 }
85}