]>
Commit | Line | Data |
---|---|---|
1 | //@ skip if $hostOS == "windows" | |
2 | ||
3 | // Verify that the dividend propagate the NeedsNegZero if the dividend requires it. | |
4 | function moduloWithNegativeZeroDividend(a, b, c) | |
5 | { | |
6 | var temp = a * b; | |
7 | return temp % c; | |
8 | } | |
9 | noInline(moduloWithNegativeZeroDividend); | |
10 | ||
11 | // Warm up with integers. The test for NegZero should not be eliminated here. | |
12 | for (var i = 1; i < 1e4; ++i) { | |
13 | var result = moduloWithNegativeZeroDividend(i, 5, 5); | |
14 | if (result !== 0) | |
15 | throw "moduloWithNegativeZeroDividend(i, 5, 5), returned: " + result; | |
16 | } | |
17 | ||
18 | for (var i = 1; i < 1e4; ++i) { | |
19 | // Produce negative zero in the multiplication. | |
20 | var result = moduloWithNegativeZeroDividend(-i, 0, 2); | |
21 | if (!(result === 0 && (1/result) === -Infinity)) | |
22 | throw "moduloWithNegativeZeroDividend(-i, 0, 2) failed, returned: " + result; | |
23 | ||
24 | // A negative dividend can produce negative zero results. | |
25 | var result = moduloWithNegativeZeroDividend(-i, 5, 5); | |
26 | if (!(result === 0 && (1/result) === -Infinity)) | |
27 | throw "moduloWithNegativeZeroDividend(-i, 5, 5) failed, returned: " + result; | |
28 | } | |
29 | ||
30 | // Edge cases. | |
31 | for (var i = 1; i < 1e4; ++i) { | |
32 | var result = moduloWithNegativeZeroDividend(-i, 0, Infinity); | |
33 | if (!(result === 0 && (1/result) === -Infinity)) | |
34 | throw "moduloWithNegativeZeroDividend(-i, 0, Infinity) failed, returned: " + result; | |
35 | ||
36 | var result = moduloWithNegativeZeroDividend(-i, 0, -Infinity); | |
37 | if (!(result === 0 && (1/result) === -Infinity)) | |
38 | throw "moduloWithNegativeZeroDividend(-i, 0, -Infinity) failed, returned: " + result; | |
39 | ||
40 | var result = moduloWithNegativeZeroDividend(-i, 0, NaN); | |
41 | if (result === result) | |
42 | throw "moduloWithNegativeZeroDividend(-i, 0, NaN) failed, returned: " + result; | |
43 | } | |
44 | ||
45 | ||
46 | // In this case, the negative zero is irrelevant. The Neg Zero check can be eliminated. | |
47 | function moduloWithUnusedNegativeZeroDividend(a, b, c) | |
48 | { | |
49 | var temp = a * b; | |
50 | return (temp % c) | 0; | |
51 | } | |
52 | noInline(moduloWithUnusedNegativeZeroDividend); | |
53 | ||
54 | for (var i = 1; i < 1e4; ++i) { | |
55 | var result = moduloWithUnusedNegativeZeroDividend(i, 5, 5); | |
56 | if (result !== 0) | |
57 | throw "moduloWithUnusedNegativeZeroDividend(i, 5, 5), returned: " + result; | |
58 | } | |
59 | ||
60 | // Produce negative zero in the multiplication. | |
61 | for (var i = 1; i < 1e4; ++i) { | |
62 | var result = moduloWithUnusedNegativeZeroDividend(-i, 0, 2); | |
63 | if (!(result === 0 && (1/result) === Infinity)) | |
64 | throw "moduloWithUnusedNegativeZeroDividend(-i, 0, 2) failed, returned: " + result; | |
65 | } | |
66 | ||
67 | for (var i = 1; i < 1e4; ++i) { | |
68 | var result = moduloWithUnusedNegativeZeroDividend(-i, 0, Infinity); | |
69 | if (!(result === 0 && (1/result) === Infinity)) | |
70 | throw "moduloWithUnusedNegativeZeroDividend(-i, 0, Infinity) failed, returned: " + result; | |
71 | ||
72 | var result = moduloWithUnusedNegativeZeroDividend(-i, 0, -Infinity); | |
73 | if (!(result === 0 && (1/result) === Infinity)) | |
74 | throw "moduloWithUnusedNegativeZeroDividend(-i, 0, -Infinity) failed, returned: " + result; | |
75 | ||
76 | var result = moduloWithUnusedNegativeZeroDividend(-i, 0, NaN); | |
77 | if (result !== 0) | |
78 | throw "moduloWithUnusedNegativeZeroDividend(-i, 0, NaN) failed, returned: " + result; | |
79 | } | |
80 | ||
81 | ||
82 | // The sign of the divisor is completely irrelevant. This should never fail on negative zero divisors. | |
83 | function moduloWithNegativeZeroDivisor(a, b, c) | |
84 | { | |
85 | var temp = a * b; | |
86 | return c % temp; | |
87 | } | |
88 | noInline(moduloWithNegativeZeroDivisor); | |
89 | ||
90 | // Warm up with integers. | |
91 | for (var i = 1; i < 1e4; ++i) { | |
92 | var result = moduloWithNegativeZeroDivisor(i, 2, i); | |
93 | if (result !== i) | |
94 | throw "moduloWithNegativeZeroDividend(i, 2, i), returned: " + result; | |
95 | ||
96 | var result = moduloWithNegativeZeroDivisor(-i, 2, i); | |
97 | if (result !== i) | |
98 | throw "moduloWithNegativeZeroDividend(-i, 2, i), returned: " + result; | |
99 | } | |
100 | ||
101 | // Produce negative zero in the multiplication. | |
102 | for (var i = 1; i < 1e4; ++i) { | |
103 | var result = moduloWithNegativeZeroDivisor(-i, 0, 2); | |
104 | if (result === result) | |
105 | throw "moduloWithNegativeZeroDivisor(-i, 0, 2) failed, returned: " + result; | |
106 | } |