benjamin@webkit.org | 88d9c89 | 2016-04-28 20:50:08 +0000 | [diff] [blame] | 1 | // This test verify the results of Math.pow() do not change as we change optimization tier. |
| 2 | |
| 3 | function opaquePow(a, b) |
| 4 | { |
| 5 | return Math.pow(a, b); |
| 6 | } |
| 7 | noInline(opaquePow); |
| 8 | |
| 9 | |
| 10 | let 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 | ]; |
| 32 | let cases = []; |
| 33 | for (let caseString of caseStrings) { |
| 34 | cases.push(eval(caseString)); |
| 35 | } |
| 36 | |
| 37 | let expectedResults = []; |
| 38 | let constantBaseFunctions = []; |
| 39 | let constantExponentFunctions = []; |
| 40 | for (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 | |
| 53 | function 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 | |
| 66 | for (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.com | baef407 | 2016-05-17 13:43:29 +0000 | [diff] [blame] | 74 | throw `Failed opaquePow with base = ${base} exponent = ${exponent} expected (${expectedResult}) got (${result})`; |
benjamin@webkit.org | 88d9c89 | 2016-04-28 20:50:08 +0000 | [diff] [blame] | 75 | |
| 76 | result = constantBaseFunctions[i](exponent); |
| 77 | if (!isIdentical(result, expectedResult)) |
utatane.tea@gmail.com | baef407 | 2016-05-17 13:43:29 +0000 | [diff] [blame] | 78 | throw `Failed constantBaseFunctions with base = ${base} exponent = ${exponent} expected (${expectedResult}) got (${result})`; |
benjamin@webkit.org | 88d9c89 | 2016-04-28 20:50:08 +0000 | [diff] [blame] | 79 | |
| 80 | result = constantExponentFunctions[j](base); |
| 81 | if (!isIdentical(result, expectedResult)) |
utatane.tea@gmail.com | baef407 | 2016-05-17 13:43:29 +0000 | [diff] [blame] | 82 | throw `Failed constantExponentFunctions with base = ${base} exponent = ${exponent} expected (${expectedResult}) got (${result})`; |
benjamin@webkit.org | 88d9c89 | 2016-04-28 20:50:08 +0000 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | } |