test262/implementation-contributed/javascriptcore/stress/math-rounding-negative-zero.js
test262-automation e9a5a7f918 [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time) (#1620)
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
2018-07-03 15:59:58 -04:00

80 lines
1.9 KiB
JavaScript

function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
function testRound(value)
{
return Math.round(value);
}
noInline(testRound);
for (var i = 0; i < 1e4; ++i) {
shouldBe(1 / testRound(-0.4), -Infinity);
shouldBe(1 / testRound(-0.5), -Infinity);
shouldBe(1 / testRound(-0.6), -1.0);
shouldBe(1 / testRound(-0.0), -Infinity);
shouldBe(1 / testRound(0.1), Infinity);
}
function testFloor(value)
{
return Math.floor(value);
}
noInline(testFloor);
for (var i = 0; i < 1e4; ++i) {
shouldBe(1 / testFloor(-0.0), -Infinity);
}
function testCeil(value)
{
return Math.ceil(value);
}
noInline(testCeil);
for (var i = 0; i < 1e4; ++i) {
shouldBe(1 / testCeil(-0.0), -Infinity);
shouldBe(1 / testCeil(-0.9), -Infinity);
}
function testRoundNonNegativeZero(value)
{
return Math.round(value) | 0;
}
noInline(testRoundNonNegativeZero);
for (var i = 0; i < 1e4; ++i) {
shouldBe(testRoundNonNegativeZero(0.4), 0);
shouldBe(testRoundNonNegativeZero(0.5), 1);
shouldBe(testRoundNonNegativeZero(0.6), 1);
shouldBe(testRoundNonNegativeZero(0.0), 0);
shouldBe(testRoundNonNegativeZero(0.1), 0);
}
shouldBe(1 / testRoundNonNegativeZero(-0.4), Infinity);
function testRoundNonNegativeZero2(value)
{
return Math.round(value) | 0;
}
noInline(testRoundNonNegativeZero2);
for (var i = 0; i < 1e4; ++i) {
shouldBe(1 / testRoundNonNegativeZero2(-0.4), Infinity);
shouldBe(1 / testRoundNonNegativeZero2(-0.5), Infinity);
shouldBe(1 / testRoundNonNegativeZero2(-0.6), -1.0);
shouldBe(1 / testRoundNonNegativeZero2(-0.0), Infinity);
shouldBe(1 / testRoundNonNegativeZero2(0.1), Infinity);
}
function testTrunc(value)
{
return Math.trunc(value);
}
noInline(testTrunc);
for (var i = 0; i < 1e4; ++i) {
shouldBe(1 / testTrunc(0.0), Infinity);
shouldBe(1 / testTrunc(-0.0), -Infinity);
}