]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - tests/stress/math-round-arith-rounding-mode.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / math-round-arith-rounding-mode.js
... / ...
CommitLineData
1function firstCareAboutZeroSecondDoesNot(a) {
2 var resultA = Math.round(a);
3 var resultB = Math.round(a)|0;
4 return { resultA:resultA, resultB:resultB };
5}
6noInline(firstCareAboutZeroSecondDoesNot);
7
8function firstDoNotCareAboutZeroSecondDoes(a) {
9 var resultA = Math.round(a)|0;
10 var resultB = Math.round(a);
11 return { resultA:resultA, resultB:resultB };
12}
13noInline(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.
17function warmup() {
18 for (var i = 0; i < 1e4; ++i) {
19 firstCareAboutZeroSecondDoesNot(42.6 + i);
20 firstDoNotCareAboutZeroSecondDoes(42.4 + i);
21 }
22}
23warmup();
24
25function 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}
44verifyNegativeZeroIsPreserved();