mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 22:40:28 +02:00
* [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)
86 lines
3.9 KiB
JavaScript
86 lines
3.9 KiB
JavaScript
function firstCareAboutZeroSecondDoesNot(a) {
|
|
var resultA = Math.floor(a);
|
|
var resultB = Math.floor(a)|0;
|
|
return { resultA:resultA, resultB:resultB };
|
|
}
|
|
noInline(firstCareAboutZeroSecondDoesNot);
|
|
|
|
function firstDoNotCareAboutZeroSecondDoes(a) {
|
|
var resultA = Math.floor(a)|0;
|
|
var resultB = Math.floor(a);
|
|
return { resultA:resultA, resultB:resultB };
|
|
}
|
|
noInline(firstDoNotCareAboutZeroSecondDoes);
|
|
|
|
// Warmup with doubles, but nothing that would floor to -0 to ensure we never
|
|
// see a double as result. The result must be integers, the input is kept to small values.
|
|
function warmup() {
|
|
for (var i = 0; i < 1e4; ++i) {
|
|
firstCareAboutZeroSecondDoesNot(42.6 + i);
|
|
firstDoNotCareAboutZeroSecondDoes(42.4 + i);
|
|
}
|
|
}
|
|
warmup();
|
|
|
|
function verifyNegativeZeroIsPreserved() {
|
|
for (var i = 0; i < 1e4; ++i) {
|
|
var result1 = firstCareAboutZeroSecondDoesNot(-0.1);
|
|
if (1 / result1.resultA !== -1) {
|
|
throw new Error("Failed firstCareAboutZeroSecondDoesNot(-0.1), resultA = " + result1.resultA);
|
|
}
|
|
if (1 / result1.resultB !== -1) {
|
|
throw new Error("Failed firstCareAboutZeroSecondDoesNot(-0.1), resultB = " + result1.resultB);
|
|
}
|
|
var result2 = firstDoNotCareAboutZeroSecondDoes(-0.1);
|
|
if (1 / result2.resultA !== -1) {
|
|
throw new Error("Failed firstDoNotCareAboutZeroSecondDoes(-0.1), resultA = " + result1.resultA);
|
|
}
|
|
if (1 / result2.resultB !== -1) {
|
|
throw new Error("Failed firstDoNotCareAboutZeroSecondDoes(-0.1), resultB = " + result1.resultB);
|
|
}
|
|
var result3 = firstCareAboutZeroSecondDoesNot(-0.0);
|
|
if (1 / result3.resultA !== -Infinity) {
|
|
throw new Error("Failed firstCareAboutZeroSecondDoesNot(-0.0), resultA = " + result3.resultA);
|
|
}
|
|
if (1 / result3.resultB !== Infinity) {
|
|
throw new Error("Failed firstCareAboutZeroSecondDoesNot(-0.0), resultB = " + result3.resultB);
|
|
}
|
|
var result4 = firstDoNotCareAboutZeroSecondDoes(-0.0);
|
|
if (1 / result4.resultA !== Infinity) {
|
|
throw new Error("Failed firstDoNotCareAboutZeroSecondDoes(-0.0), resultA = " + result4.resultA);
|
|
}
|
|
if (1 / result4.resultB !== -Infinity) {
|
|
throw new Error("Failed firstDoNotCareAboutZeroSecondDoes(-0.0), resultB = " + result4.resultB);
|
|
}
|
|
var result5 = firstCareAboutZeroSecondDoesNot(0.0);
|
|
if (1 / result5.resultA !== Infinity) {
|
|
throw new Error("Failed firstCareAboutZeroSecondDoesNot(0.0), resultA = " + result5.resultA);
|
|
}
|
|
if (1 / result5.resultB !== Infinity) {
|
|
throw new Error("Failed firstCareAboutZeroSecondDoesNot(0.0), resultB = " + result5.resultB);
|
|
}
|
|
var result6 = firstDoNotCareAboutZeroSecondDoes(0.0);
|
|
if (1 / result6.resultA !== Infinity) {
|
|
throw new Error("Failed firstDoNotCareAboutZeroSecondDoes(0.0), resultA = " + result6.resultA);
|
|
}
|
|
if (1 / result6.resultB !== Infinity) {
|
|
throw new Error("Failed firstDoNotCareAboutZeroSecondDoes(0.0), resultB = " + result6.resultB);
|
|
}
|
|
var result7 = firstCareAboutZeroSecondDoesNot(0.1);
|
|
if (1 / result7.resultA !== Infinity) {
|
|
throw new Error("Failed firstCareAboutZeroSecondDoesNot(0.1), resultA = " + result7.resultA);
|
|
}
|
|
if (1 / result7.resultB !== Infinity) {
|
|
throw new Error("Failed firstCareAboutZeroSecondDoesNot(0.1), resultB = " + result7.resultB);
|
|
}
|
|
var result8 = firstDoNotCareAboutZeroSecondDoes(0.1);
|
|
if (1 / result8.resultA !== Infinity) {
|
|
throw new Error("Failed firstDoNotCareAboutZeroSecondDoes(0.1), resultA = " + result8.resultA);
|
|
}
|
|
if (1 / result8.resultB !== Infinity) {
|
|
throw new Error("Failed firstDoNotCareAboutZeroSecondDoes(0.1), resultB = " + result8.resultB);
|
|
}
|
|
}
|
|
}
|
|
verifyNegativeZeroIsPreserved();
|