OLD | NEW |
(Empty) | |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 var x; |
| 29 |
| 30 // Converts a number to string respecting -0. |
| 31 function stringify(n) { |
| 32 if ((1 / n) === -Infinity) return "-0"; |
| 33 return String(n); |
| 34 } |
| 35 |
| 36 function f(expected, y) { |
| 37 function testEval(string, x, y) { |
| 38 var mulFunction = Function("x, y", "return " + string); |
| 39 return mulFunction(x, y); |
| 40 } |
| 41 function mulTest(expected, x, y) { |
| 42 assertEquals(expected, x * y); |
| 43 assertEquals(expected, testEval(stringify(x) + " * y", x, y)); |
| 44 assertEquals(expected, testEval("x * " + stringify(y), x, y)); |
| 45 assertEquals(expected, testEval(stringify(x) + " * " + stringify(y), x, y)); |
| 46 } |
| 47 mulTest(expected, x, y); |
| 48 mulTest(-expected, -x, y); |
| 49 mulTest(-expected, x, -y); |
| 50 mulTest(expected, -x, -y); |
| 51 if (x === y) return; // Symmetric cases not necessary. |
| 52 mulTest(expected, y, x); |
| 53 mulTest(-expected, -y, x); |
| 54 mulTest(-expected, y, -x); |
| 55 mulTest(expected, -y, -x); |
| 56 } |
| 57 |
| 58 x = 262143; |
| 59 f(0, 0); |
| 60 f(262143, 1); |
| 61 f(524286, 2); |
| 62 f(786429, 3); |
| 63 f(1048572, 4); |
| 64 f(1310715, 5); |
| 65 f(1835001, 7); |
| 66 f(2097144, 8); |
| 67 f(2359287, 9); |
| 68 f(3932145, 15); |
| 69 f(4194288, 16); |
| 70 f(4456431, 17); |
| 71 f(8126433, 31); |
| 72 f(8388576, 32); |
| 73 f(8650719, 33); |
| 74 f(16515009, 63); |
| 75 f(16777152, 64); |
| 76 f(17039295, 65); |
| 77 f(33292161, 127); |
| 78 f(33554304, 128); |
| 79 f(33816447, 129); |
| 80 f(66846465, 255); |
| 81 f(67108608, 256); |
| 82 f(67370751, 257); |
| 83 f(133955073, 511); |
| 84 f(134217216, 512); |
| 85 f(134479359, 513); |
| 86 f(268172289, 1023); |
| 87 f(268434432, 1024); |
| 88 f(268696575, 1025); |
| 89 f(536606721, 2047); |
| 90 f(536868864, 2048); |
| 91 f(537131007, 2049); |
| 92 f(1073475585, 4095); |
| 93 f(1073737728, 4096); |
| 94 f(1073999871, 4097); |
| 95 f(2147213313, 8191); |
| 96 f(2147475456, 8192); |
| 97 f(2147737599, 8193); |
| 98 f(4294688769, 16383); |
| 99 f(4294950912, 16384); |
| 100 f(4295213055, 16385); |
| 101 f(8589639681, 32767); |
| 102 f(8589901824, 32768); |
| 103 f(8590163967, 32769); |
| 104 f(17179541505, 65535); |
| 105 f(17179803648, 65536); |
| 106 f(17180065791, 65537); |
| 107 f(34359345153, 131071); |
| 108 f(34359607296, 131072); |
| 109 f(34359869439, 131073); |
| 110 f(68718952449, 262143); |
| 111 x = 262144; |
| 112 f(0, 0); |
| 113 f(262144, 1); |
| 114 f(524288, 2); |
| 115 f(786432, 3); |
| 116 f(1048576, 4); |
| 117 f(1310720, 5); |
| 118 f(1835008, 7); |
| 119 f(2097152, 8); |
| 120 f(2359296, 9); |
| 121 f(3932160, 15); |
| 122 f(4194304, 16); |
| 123 f(4456448, 17); |
| 124 f(8126464, 31); |
| 125 f(8388608, 32); |
| 126 f(8650752, 33); |
| 127 f(16515072, 63); |
| 128 f(16777216, 64); |
| 129 f(17039360, 65); |
| 130 f(33292288, 127); |
| 131 f(33554432, 128); |
| 132 f(33816576, 129); |
| 133 f(66846720, 255); |
| 134 f(67108864, 256); |
| 135 f(67371008, 257); |
| 136 f(133955584, 511); |
| 137 f(134217728, 512); |
| 138 f(134479872, 513); |
| 139 f(268173312, 1023); |
| 140 f(268435456, 1024); |
| 141 f(268697600, 1025); |
| 142 f(536608768, 2047); |
| 143 f(536870912, 2048); |
| 144 f(537133056, 2049); |
| 145 f(1073479680, 4095); |
| 146 f(1073741824, 4096); |
| 147 f(1074003968, 4097); |
| 148 f(2147221504, 8191); |
| 149 f(2147483648, 8192); |
| 150 f(2147745792, 8193); |
| 151 f(4294705152, 16383); |
| 152 f(4294967296, 16384); |
| 153 f(4295229440, 16385); |
| 154 f(8589672448, 32767); |
| 155 f(8589934592, 32768); |
| 156 f(8590196736, 32769); |
| 157 f(17179607040, 65535); |
| 158 f(17179869184, 65536); |
| 159 f(17180131328, 65537); |
| 160 f(34359476224, 131071); |
| 161 f(34359738368, 131072); |
| 162 f(34360000512, 131073); |
| 163 f(68719214592, 262143); |
| 164 f(68719476736, 262144); |
| 165 x = 262145; |
| 166 f(0, 0); |
| 167 f(262145, 1); |
| 168 f(524290, 2); |
| 169 f(786435, 3); |
| 170 f(1048580, 4); |
| 171 f(1310725, 5); |
| 172 f(1835015, 7); |
| 173 f(2097160, 8); |
| 174 f(2359305, 9); |
| 175 f(3932175, 15); |
| 176 f(4194320, 16); |
| 177 f(4456465, 17); |
| 178 f(8126495, 31); |
| 179 f(8388640, 32); |
| 180 f(8650785, 33); |
| 181 f(16515135, 63); |
| 182 f(16777280, 64); |
| 183 f(17039425, 65); |
| 184 f(33292415, 127); |
| 185 f(33554560, 128); |
| 186 f(33816705, 129); |
| 187 f(66846975, 255); |
| 188 f(67109120, 256); |
| 189 f(67371265, 257); |
| 190 f(133956095, 511); |
| 191 f(134218240, 512); |
| 192 f(134480385, 513); |
| 193 f(268174335, 1023); |
| 194 f(268436480, 1024); |
| 195 f(268698625, 1025); |
| 196 f(536610815, 2047); |
| 197 f(536872960, 2048); |
| 198 f(537135105, 2049); |
| 199 f(1073483775, 4095); |
| 200 f(1073745920, 4096); |
| 201 f(1074008065, 4097); |
| 202 f(2147229695, 8191); |
| 203 f(2147491840, 8192); |
| 204 f(2147753985, 8193); |
| 205 f(4294721535, 16383); |
| 206 f(4294983680, 16384); |
| 207 f(4295245825, 16385); |
| 208 f(8589705215, 32767); |
| 209 f(8589967360, 32768); |
| 210 f(8590229505, 32769); |
| 211 f(17179672575, 65535); |
| 212 f(17179934720, 65536); |
| 213 f(17180196865, 65537); |
| 214 f(34359607295, 131071); |
| 215 f(34359869440, 131072); |
| 216 f(34360131585, 131073); |
| 217 f(68719476735, 262143); |
| 218 f(68719738880, 262144); |
| 219 f(68720001025, 262145); |
| 220 x = 524287; |
| 221 f(0, 0); |
| 222 f(524287, 1); |
| 223 f(1048574, 2); |
| 224 f(1572861, 3); |
| 225 f(2097148, 4); |
| 226 f(2621435, 5); |
| 227 f(3670009, 7); |
| 228 f(4194296, 8); |
| 229 f(4718583, 9); |
| 230 f(7864305, 15); |
| 231 f(8388592, 16); |
| 232 f(8912879, 17); |
| 233 f(16252897, 31); |
| 234 f(16777184, 32); |
| 235 f(17301471, 33); |
| 236 f(33030081, 63); |
| 237 f(33554368, 64); |
| 238 f(34078655, 65); |
| 239 f(66584449, 127); |
| 240 f(67108736, 128); |
| 241 f(67633023, 129); |
| 242 f(133693185, 255); |
| 243 f(134217472, 256); |
| 244 f(134741759, 257); |
| 245 f(267910657, 511); |
| 246 f(268434944, 512); |
| 247 f(268959231, 513); |
| 248 f(536345601, 1023); |
| 249 f(536869888, 1024); |
| 250 f(537394175, 1025); |
| 251 f(1073215489, 2047); |
| 252 f(1073739776, 2048); |
| 253 f(1074264063, 2049); |
| 254 f(2146955265, 4095); |
| 255 f(2147479552, 4096); |
| 256 f(2148003839, 4097); |
| 257 f(4294434817, 8191); |
| 258 f(4294959104, 8192); |
| 259 f(4295483391, 8193); |
| 260 f(8589393921, 16383); |
| 261 f(8589918208, 16384); |
| 262 f(8590442495, 16385); |
| 263 f(17179312129, 32767); |
| 264 f(17179836416, 32768); |
| 265 f(17180360703, 32769); |
| 266 f(34359148545, 65535); |
| 267 f(34359672832, 65536); |
| 268 f(34360197119, 65537); |
| 269 f(68718821377, 131071); |
| 270 f(68719345664, 131072); |
| 271 f(68719869951, 131073); |
| 272 f(137438167041, 262143); |
| 273 f(137438691328, 262144); |
| 274 f(137439215615, 262145); |
| 275 f(274876858369, 524287); |
| 276 x = 524288; |
| 277 f(0, 0); |
| 278 f(524288, 1); |
| 279 f(1048576, 2); |
| 280 f(1572864, 3); |
| 281 f(2097152, 4); |
| 282 f(2621440, 5); |
| 283 f(3670016, 7); |
| 284 f(4194304, 8); |
| 285 f(4718592, 9); |
| 286 f(7864320, 15); |
| 287 f(8388608, 16); |
| 288 f(8912896, 17); |
| 289 f(16252928, 31); |
| 290 f(16777216, 32); |
| 291 f(17301504, 33); |
| 292 f(33030144, 63); |
| 293 f(33554432, 64); |
| 294 f(34078720, 65); |
| 295 f(66584576, 127); |
| 296 f(67108864, 128); |
| 297 f(67633152, 129); |
| 298 f(133693440, 255); |
| 299 f(134217728, 256); |
| 300 f(134742016, 257); |
| 301 f(267911168, 511); |
| 302 f(268435456, 512); |
| 303 f(268959744, 513); |
| 304 f(536346624, 1023); |
| 305 f(536870912, 1024); |
| 306 f(537395200, 1025); |
| 307 f(1073217536, 2047); |
| 308 f(1073741824, 2048); |
| 309 f(1074266112, 2049); |
| 310 f(2146959360, 4095); |
| 311 f(2147483648, 4096); |
| 312 f(2148007936, 4097); |
| 313 f(4294443008, 8191); |
| 314 f(4294967296, 8192); |
| 315 f(4295491584, 8193); |
| 316 f(8589410304, 16383); |
| 317 f(8589934592, 16384); |
| 318 f(8590458880, 16385); |
| 319 f(17179344896, 32767); |
| 320 f(17179869184, 32768); |
| 321 f(17180393472, 32769); |
| 322 f(34359214080, 65535); |
| 323 f(34359738368, 65536); |
| 324 f(34360262656, 65537); |
| 325 f(68718952448, 131071); |
| 326 f(68719476736, 131072); |
| 327 f(68720001024, 131073); |
| 328 f(137438429184, 262143); |
| 329 f(137438953472, 262144); |
| 330 f(137439477760, 262145); |
| 331 f(274877382656, 524287); |
| 332 f(274877906944, 524288); |
| 333 x = 524289; |
| 334 f(0, 0); |
| 335 f(524289, 1); |
| 336 f(1048578, 2); |
| 337 f(1572867, 3); |
| 338 f(2097156, 4); |
| 339 f(2621445, 5); |
| 340 f(3670023, 7); |
| 341 f(4194312, 8); |
| 342 f(4718601, 9); |
| 343 f(7864335, 15); |
| 344 f(8388624, 16); |
| 345 f(8912913, 17); |
| 346 f(16252959, 31); |
| 347 f(16777248, 32); |
| 348 f(17301537, 33); |
| 349 f(33030207, 63); |
| 350 f(33554496, 64); |
| 351 f(34078785, 65); |
| 352 f(66584703, 127); |
| 353 f(67108992, 128); |
| 354 f(67633281, 129); |
| 355 f(133693695, 255); |
| 356 f(134217984, 256); |
| 357 f(134742273, 257); |
| 358 f(267911679, 511); |
| 359 f(268435968, 512); |
| 360 f(268960257, 513); |
| 361 f(536347647, 1023); |
| 362 f(536871936, 1024); |
| 363 f(537396225, 1025); |
| 364 f(1073219583, 2047); |
| 365 f(1073743872, 2048); |
| 366 f(1074268161, 2049); |
| 367 f(2146963455, 4095); |
| 368 f(2147487744, 4096); |
| 369 f(2148012033, 4097); |
| 370 f(4294451199, 8191); |
| 371 f(4294975488, 8192); |
| 372 f(4295499777, 8193); |
| 373 f(8589426687, 16383); |
| 374 f(8589950976, 16384); |
| 375 f(8590475265, 16385); |
| 376 f(17179377663, 32767); |
| 377 f(17179901952, 32768); |
| 378 f(17180426241, 32769); |
| 379 f(34359279615, 65535); |
| 380 f(34359803904, 65536); |
| 381 f(34360328193, 65537); |
| 382 f(68719083519, 131071); |
| 383 f(68719607808, 131072); |
| 384 f(68720132097, 131073); |
| 385 f(137438691327, 262143); |
| 386 f(137439215616, 262144); |
| 387 f(137439739905, 262145); |
| 388 f(274877906943, 524287); |
| 389 f(274878431232, 524288); |
| 390 f(274878955521, 524289); |
| 391 x = 1048575; |
| 392 f(0, 0); |
| 393 f(1048575, 1); |
| 394 f(2097150, 2); |
| 395 f(3145725, 3); |
| 396 f(4194300, 4); |
| 397 f(5242875, 5); |
| 398 f(7340025, 7); |
| 399 f(8388600, 8); |
| 400 f(9437175, 9); |
| 401 f(15728625, 15); |
| 402 f(16777200, 16); |
| 403 f(17825775, 17); |
| 404 f(32505825, 31); |
| 405 f(33554400, 32); |
| 406 f(34602975, 33); |
| 407 f(66060225, 63); |
| 408 f(67108800, 64); |
| 409 f(68157375, 65); |
| 410 f(133169025, 127); |
| 411 f(134217600, 128); |
| 412 f(135266175, 129); |
| 413 f(267386625, 255); |
| 414 f(268435200, 256); |
| 415 f(269483775, 257); |
| 416 f(535821825, 511); |
| 417 f(536870400, 512); |
| 418 f(537918975, 513); |
| 419 f(1072692225, 1023); |
| 420 f(1073740800, 1024); |
| 421 f(1074789375, 1025); |
| 422 f(2146433025, 2047); |
| 423 f(2147481600, 2048); |
| 424 f(2148530175, 2049); |
| 425 f(4293914625, 4095); |
| 426 f(4294963200, 4096); |
| 427 f(4296011775, 4097); |
| 428 f(8588877825, 8191); |
| 429 f(8589926400, 8192); |
| 430 f(8590974975, 8193); |
| 431 f(17178804225, 16383); |
| 432 f(17179852800, 16384); |
| 433 f(17180901375, 16385); |
| 434 f(34358657025, 32767); |
| 435 f(34359705600, 32768); |
| 436 f(34360754175, 32769); |
| 437 f(68718362625, 65535); |
| 438 f(68719411200, 65536); |
| 439 f(68720459775, 65537); |
| 440 f(137437773825, 131071); |
| 441 f(137438822400, 131072); |
| 442 f(137439870975, 131073); |
| 443 f(274876596225, 262143); |
| 444 f(274877644800, 262144); |
| 445 f(274878693375, 262145); |
| 446 f(549754241025, 524287); |
| 447 f(549755289600, 524288); |
| 448 f(549756338175, 524289); |
| 449 f(1099509530625, 1048575); |
| 450 x = 1048576; |
| 451 f(0, 0); |
| 452 f(1048576, 1); |
| 453 f(2097152, 2); |
| 454 f(3145728, 3); |
| 455 f(4194304, 4); |
| 456 f(5242880, 5); |
| 457 f(7340032, 7); |
| 458 f(8388608, 8); |
| 459 f(9437184, 9); |
| 460 f(15728640, 15); |
| 461 f(16777216, 16); |
| 462 f(17825792, 17); |
| 463 f(32505856, 31); |
| 464 f(33554432, 32); |
| 465 f(34603008, 33); |
| 466 f(66060288, 63); |
| 467 f(67108864, 64); |
| 468 f(68157440, 65); |
| 469 f(133169152, 127); |
| 470 f(134217728, 128); |
| 471 f(135266304, 129); |
| 472 f(267386880, 255); |
| 473 f(268435456, 256); |
| 474 f(269484032, 257); |
| 475 f(535822336, 511); |
| 476 f(536870912, 512); |
| 477 f(537919488, 513); |
| 478 f(1072693248, 1023); |
| 479 f(1073741824, 1024); |
| 480 f(1074790400, 1025); |
| 481 f(2146435072, 2047); |
| 482 f(2147483648, 2048); |
| 483 f(2148532224, 2049); |
| 484 f(4293918720, 4095); |
| 485 f(4294967296, 4096); |
| 486 f(4296015872, 4097); |
| 487 f(8588886016, 8191); |
| 488 f(8589934592, 8192); |
| 489 f(8590983168, 8193); |
| 490 f(17178820608, 16383); |
| 491 f(17179869184, 16384); |
| 492 f(17180917760, 16385); |
| 493 f(34358689792, 32767); |
| 494 f(34359738368, 32768); |
| 495 f(34360786944, 32769); |
| 496 f(68718428160, 65535); |
| 497 f(68719476736, 65536); |
| 498 f(68720525312, 65537); |
| 499 f(137437904896, 131071); |
| 500 f(137438953472, 131072); |
| 501 f(137440002048, 131073); |
| 502 f(274876858368, 262143); |
| 503 f(274877906944, 262144); |
| 504 f(274878955520, 262145); |
| 505 f(549754765312, 524287); |
| 506 f(549755813888, 524288); |
| 507 f(549756862464, 524289); |
| 508 f(1099510579200, 1048575); |
| 509 f(1099511627776, 1048576); |
OLD | NEW |