OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 var zero = 0; | 162 var zero = 0; |
163 var minsmi32 = -0x40000000; | 163 var minsmi32 = -0x40000000; |
164 var minsmi64 = -0x80000000; | 164 var minsmi64 = -0x80000000; |
165 var somenum = 3532; | 165 var somenum = 3532; |
166 assertEquals(-0, zero / -1, "0 / -1"); | 166 assertEquals(-0, zero / -1, "0 / -1"); |
167 assertEquals(1, minsmi32 / -0x40000000, "minsmi/minsmi-32"); | 167 assertEquals(1, minsmi32 / -0x40000000, "minsmi/minsmi-32"); |
168 assertEquals(1, minsmi64 / -0x80000000, "minsmi/minsmi-64"); | 168 assertEquals(1, minsmi64 / -0x80000000, "minsmi/minsmi-64"); |
169 assertEquals(somenum, somenum % -0x40000000, "%minsmi-32"); | 169 assertEquals(somenum, somenum % -0x40000000, "%minsmi-32"); |
170 assertEquals(somenum, somenum % -0x80000000, "%minsmi-64"); | 170 assertEquals(somenum, somenum % -0x80000000, "%minsmi-64"); |
171 })(); | 171 })(); |
| 172 |
| 173 |
| 174 // Side-effect-free expressions containing bit operations use |
| 175 // an optimized compiler with int32 values. Ensure that modulus |
| 176 // produces negative zeros correctly. |
| 177 function negative_zero_modulus_test() { |
| 178 var x = 4; |
| 179 var y = -4; |
| 180 x = x + x - x; |
| 181 y = y + y - y; |
| 182 var z = (y | y | y | y) % x; |
| 183 assertEquals(-1 / 0, 1 / z); |
| 184 z = (x | x | x | x) % x; |
| 185 assertEquals(1 / 0, 1 / z); |
| 186 z = (y | y | y | y) % y; |
| 187 assertEquals(-1 / 0, 1 / z); |
| 188 z = (x | x | x | x) % y; |
| 189 assertEquals(1 / 0, 1 / z); |
| 190 } |
| 191 |
| 192 negative_zero_modulus_test(); |
OLD | NEW |