]>
Commit | Line | Data |
---|---|---|
1 | function firstCareAboutZeroSecondDoesNot(a) { | |
2 | var resultA = Math.round(a); | |
3 | var resultB = Math.round(a)|0; | |
4 | return { resultA:resultA, resultB:resultB }; | |
5 | } | |
6 | noInline(firstCareAboutZeroSecondDoesNot); | |
7 | ||
8 | function firstDoNotCareAboutZeroSecondDoes(a) { | |
9 | var resultA = Math.round(a)|0; | |
10 | var resultB = Math.round(a); | |
11 | return { resultA:resultA, resultB:resultB }; | |
12 | } | |
13 | noInline(firstDoNotCareAboutZeroSecondDoes); | |
14 | ||
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. | |
17 | function warmup() { | |
18 | for (var i = 0; i < 1e4; ++i) { | |
19 | firstCareAboutZeroSecondDoesNot(42.6 + i); | |
20 | firstDoNotCareAboutZeroSecondDoes(42.4 + i); | |
21 | } | |
22 | } | |
23 | warmup(); | |
24 | ||
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; | |
30 | } | |
31 | if (1 / result1.resultB !== Infinity) { | |
32 | throw "Failed firstCareAboutZeroSecondDoesNot(-0.1), resultB = " + result1.resultB; | |
33 | } | |
34 | var result2 = firstDoNotCareAboutZeroSecondDoes(-0.1); | |
35 | if (1 / result2.resultA !== Infinity) { | |
36 | throw "Failed firstDoNotCareAboutZeroSecondDoes(-0.1), resultA = " + result1.resultA; | |
37 | } | |
38 | if (1 / result2.resultB !== -Infinity) { | |
39 | throw "Failed firstDoNotCareAboutZeroSecondDoes(-0.1), resultB = " + result1.resultB; | |
40 | } | |
41 | ||
42 | } | |
43 | } | |
44 | verifyNegativeZeroIsPreserved(); |