Skip to content

Commit 7496ff1

Browse files
sisyphuskhwilliamson
authored andcommitted
Amend documentation of shift operators in perlop.pod.
1 parent 1e1959c commit 7496ff1

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

pod/perlop.pod

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -480,22 +480,17 @@ Shifting by negative number of bits means the reverse shift: left
480480
shift becomes right shift, right shift becomes left shift. This is
481481
unlike in C, where negative shift is undefined.
482482

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.
492487

493488
If you get tired of being subject to your platform's native integers,
494489
the S<C<use bigint>> pragma neatly sidesteps the issue altogether:
495490

496491
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
499494
use bigint;
500495
print 20 << 100; # 25353012004564588029934064107520
501496

0 commit comments

Comments
 (0)