michael@0: // Test Math.round() for IonMonkey. michael@0: // Requires --ion-eager to enter at the top of each loop. michael@0: michael@0: var roundDTests = [ michael@0: [-0, -0], michael@0: [0.49999999999999997, 1], michael@0: [0.5, 1], michael@0: [1.0, 1], michael@0: [1.5, 2], michael@0: [792.8, 793], michael@0: [-0.1, -0], michael@0: [-1.0001, -1], michael@0: [-3.14, -3], michael@0: [2137483649.5, 2137483650], michael@0: [2137483648.5, 2137483649], michael@0: [2137483647.1, 2137483647], michael@0: [900000000000, 900000000000], michael@0: [-0, -0], michael@0: [-Infinity, -Infinity], michael@0: [Infinity, Infinity], michael@0: [NaN, NaN], michael@0: [-2147483648.8, -2147483649], michael@0: [-2147483649.8, -2147483650] michael@0: ]; michael@0: michael@0: var roundITests = [ michael@0: [0, 0], michael@0: [4, 4], michael@0: [2147483648, 2147483648], michael@0: [-2147483649, -2147483649] michael@0: ]; michael@0: michael@0: // Typed functions to be compiled by Ion. michael@0: function roundD(x) { return Math.round(x); } michael@0: function roundI(x) { return Math.round(x); } michael@0: michael@0: function test() { michael@0: // Always run this function in the interpreter. michael@0: try {} catch (e) {} michael@0: michael@0: for (var i = 0; i < roundDTests.length; i++) michael@0: assertEq(roundD(roundDTests[i][0]), roundDTests[i][1]); michael@0: for (var i = 0; i < roundITests.length; i++) michael@0: assertEq(roundI(roundITests[i][0]), roundITests[i][1]); michael@0: } michael@0: michael@0: for (var i = 0; i < 40; i++) michael@0: test();