@@ -480,22 +480,17 @@ Shifting by negative number of bits means the reverse shift: left
480
480
shift becomes right shift, right shift becomes left shift. This is
481
481
unlike in C, where negative shift is undefined.
482
482
483
- Shifting by more bits than the size of the integers means most of the
484
- time zero (all bits fall off), except that under S<C<use integer>>
485
- right overshifting a negative shiftee results in -1. This is unlike
486
- in C, where shifting by too many bits is undefined. A common C
487
- behavior is "shift by modulo wordbits", so that for example
488
-
489
- 1 >> 64 == 1 >> (64 % 64) == 1 >> 0 == 1 # Common C behavior.
490
-
491
- but that is completely accidental.
483
+ Shifting by a value greater than or equal to integer size (in bits)
484
+ results in zero (all bits fall off), except that under S<C<use integer>>
485
+ right shifting a negative value by such an amount results in -1.
486
+ This is unlike in C, where shifting by too many bits is undefined.
492
487
493
488
If you get tired of being subject to your platform's native integers,
494
489
the S<C<use bigint>> pragma neatly sidesteps the issue altogether:
495
490
496
491
print 20 << 20; # 20971520
497
- print 20 << 40 ; # 5120 on 32-bit machines ,
498
- # 21990232555520 on 64-bit machines
492
+ print 20 << 32 ; # 0 with 32-bit integer ,
493
+ # 85899345920 with 64-bit integer
499
494
use bigint;
500
495
print 20 << 100; # 25353012004564588029934064107520
501
496
0 commit comments