OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 // End block A repeat 2 | 530 // End block A repeat 2 |
531 | 531 |
532 // Repeat previous block, with computed values in the shift variables. | 532 // Repeat previous block, with computed values in the shift variables. |
533 five = 0; | 533 five = 0; |
534 while (five < 5 ) ++five; | 534 while (five < 5 ) ++five; |
535 four = five - one; | 535 four = five - one; |
536 three = four - one; | 536 three = four - one; |
537 one = four - three; | 537 one = four - three; |
538 zero = one - one; | 538 zero = one - one; |
539 | 539 |
540 // Begin block A repeat 3 | 540 // Begin block A repeat 3 |
541 assertEquals(pos_non_smi, (pos_non_smi) >> zero); | 541 assertEquals(pos_non_smi, (pos_non_smi) >> zero); |
542 assertEquals(pos_non_smi, (pos_non_smi) >>> zero); | 542 assertEquals(pos_non_smi, (pos_non_smi) >>> zero); |
543 assertEquals(pos_non_smi, (pos_non_smi) << zero); | 543 assertEquals(pos_non_smi, (pos_non_smi) << zero); |
544 assertEquals(neg_non_smi, (neg_non_smi) >> zero); | 544 assertEquals(neg_non_smi, (neg_non_smi) >> zero); |
545 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero); | 545 assertEquals(neg_non_smi + 0x100000000, (neg_non_smi) >>> zero); |
546 assertEquals(neg_non_smi, (neg_non_smi) << zero); | 546 assertEquals(neg_non_smi, (neg_non_smi) << zero); |
547 assertEquals(pos_smi, (pos_smi) >> zero); | 547 assertEquals(pos_smi, (pos_smi) >> zero); |
548 assertEquals(pos_smi, (pos_smi) >>> zero); | 548 assertEquals(pos_smi, (pos_smi) >>> zero); |
549 assertEquals(pos_smi, (pos_smi) << zero); | 549 assertEquals(pos_smi, (pos_smi) << zero); |
550 assertEquals(neg_smi, (neg_smi) >> zero, "negsmi >> zero(2)"); | 550 assertEquals(neg_smi, (neg_smi) >> zero, "negsmi >> zero(2)"); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 var shift = 2.4; | 631 var shift = 2.4; |
632 assertEquals(5, 20.5 >> shift); | 632 assertEquals(5, 20.5 >> shift); |
633 assertEquals(5, 20.5 >> shift + 0.3); | 633 assertEquals(5, 20.5 >> shift + 0.3); |
634 shift = shift + zero; | 634 shift = shift + zero; |
635 assertEquals(5, 20.5 >> shift); | 635 assertEquals(5, 20.5 >> shift); |
636 assertEquals(5, 20.5 >> shift + 0.3); | 636 assertEquals(5, 20.5 >> shift + 0.3); |
637 } | 637 } |
638 | 638 |
639 testShiftNonSmis(); | 639 testShiftNonSmis(); |
640 | 640 |
| 641 function intConversion() { |
| 642 function foo(x) { |
| 643 assertEquals(x, (x * 1.0000000001) | 0, "foo more " + x); |
| 644 assertEquals(x, x | 0, "foo " + x); |
| 645 if (x > 0) { |
| 646 assertEquals(x - 1, (x * 0.9999999999) | 0, "foo less " + x); |
| 647 } else { |
| 648 assertEquals(x + 1, (x * 0.9999999999) | 0, "foo less " + x); |
| 649 } |
| 650 } |
| 651 for (var i = 1; i < 0x80000000; i *= 2) { |
| 652 foo(i); |
| 653 foo(-i); |
| 654 } |
| 655 for (var i = 1; i < 1/0; i *= 2) { |
| 656 assertEquals(i | 0, (i * 1.0000000000000001) | 0, "b" + i); |
| 657 assertEquals(-i | 0, (i * -1.0000000000000001) | 0, "c" + i); |
| 658 } |
| 659 for (var i = 0.5; i > 0; i /= 2) { |
| 660 assertEquals(0, i | 0, "d" + i); |
| 661 assertEquals(0, -i | 0, "e" + i); |
| 662 } |
| 663 } |
| 664 |
| 665 intConversion(); |
641 | 666 |
642 // Verify that we handle the (optimized) corner case of shifting by | 667 // Verify that we handle the (optimized) corner case of shifting by |
643 // zero even for non-smis. | 668 // zero even for non-smis. |
644 function shiftByZero(n) { return n << 0; } | 669 function shiftByZero(n) { return n << 0; } |
645 | 670 |
646 assertEquals(3, shiftByZero(3.1415)); | 671 assertEquals(3, shiftByZero(3.1415)); |
OLD | NEW |