1 function firstCareAboutZeroSecondDoesNot(a
) {
2 var resultA
= Math
.round(a
);
3 var resultB
= Math
.round(a
)|0;
4 return { resultA:resultA
, resultB:resultB
};
6 noInline(firstCareAboutZeroSecondDoesNot
);
8 function firstDoNotCareAboutZeroSecondDoes(a
) {
9 var resultA
= Math
.round(a
)|0;
10 var resultB
= Math
.round(a
);
11 return { resultA:resultA
, resultB:resultB
};
13 noInline(firstDoNotCareAboutZeroSecondDoes
);
15 // Warmup with doubles, but nothing that would round to -0 to ensure we never
16 // see a double as result. The result must be integers, the input is kept to small values.
18 for (var i
= 0; i
< 1e4
; ++i
) {
19 firstCareAboutZeroSecondDoesNot(42.6 + i
);
20 firstDoNotCareAboutZeroSecondDoes(42.4 + i
);
25 function verifyNegativeZeroIsPreserved() {
26 for (var i
= 0; i
< 1e4
; ++i
) {
27 var result1
= firstCareAboutZeroSecondDoesNot(-0.1);
28 if (1 / result1
.resultA
!== -Infinity
) {
29 throw "Failed firstCareAboutZeroSecondDoesNot(-0.1), resultA = " + result1
.resultA
;
31 if (1 / result1
.resultB
!== Infinity
) {
32 throw "Failed firstCareAboutZeroSecondDoesNot(-0.1), resultB = " + result1
.resultB
;
34 var result2
= firstDoNotCareAboutZeroSecondDoes(-0.1);
35 if (1 / result2
.resultA
!== Infinity
) {
36 throw "Failed firstDoNotCareAboutZeroSecondDoes(-0.1), resultA = " + result1
.resultA
;
38 if (1 / result2
.resultB
!== -Infinity
) {
39 throw "Failed firstDoNotCareAboutZeroSecondDoes(-0.1), resultB = " + result1
.resultB
;
44 verifyNegativeZeroIsPreserved();