From 3c35aa2e53f6c3699931a6343c51e2db56519583 Mon Sep 17 00:00:00 2001 From: sisyphus Date: Sun, 15 Dec 2024 17:22:25 +1100 Subject: [PATCH] Amend documentation of shift operators in perlop.pod. --- pod/perlop.pod | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/pod/perlop.pod b/pod/perlop.pod index b19a2348b2b2..a706c7a81e41 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -480,22 +480,17 @@ Shifting by negative number of bits means the reverse shift: left shift becomes right shift, right shift becomes left shift. This is unlike in C, where negative shift is undefined. -Shifting by more bits than the size of the integers means most of the -time zero (all bits fall off), except that under S> -right overshifting a negative shiftee results in -1. This is unlike -in C, where shifting by too many bits is undefined. A common C -behavior is "shift by modulo wordbits", so that for example - - 1 >> 64 == 1 >> (64 % 64) == 1 >> 0 == 1 # Common C behavior. - -but that is completely accidental. +Shifting by a value greater than or equal to integer size (in bits) +results in zero (all bits fall off), except that under S> +right shifting a negative value by such an amount results in -1. +This is unlike in C, where shifting by too many bits is undefined. If you get tired of being subject to your platform's native integers, the S> pragma neatly sidesteps the issue altogether: print 20 << 20; # 20971520 - print 20 << 40; # 5120 on 32-bit machines, - # 21990232555520 on 64-bit machines + print 20 << 32; # 0 on 32-bit machines, + # 85899345920 on 64-bit machines use bigint; print 20 << 100; # 25353012004564588029934064107520