Skip Menu |
Report information
Id: 131278
Status: resolved
Priority: 0/
Queue: perl6

Owner: cpan [at] zoffix.com
Requestors: curt [at] tilmes.org
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] bit shift broken at 32 bits
To: rakudobug [...] perl.org
From: Curt Tilmes <curt [...] tilmes.org>
Date: Tue, 9 May 2017 12:49:04 -0400
Download (untitled) / with headers
text/plain 881b
<curt_> m: my $i = -0x8000000000000000; say ($i div 2**12) == ($i +> 12) ?? 'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5: OUTPUT: «good␤»
<curt_> m: my $i = -0x8000000000000000; say ($i div 2**37) == ($i +> 37) ?? 'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5: OUTPUT: «bad␤»
<curt_> m: my $i = -0x8000000000000000; say ($i div 2**23) == ($i +> 23) ?? 'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5: OUTPUT: «good␤»
<curt_> m: my $i = -0x8000000000000000; say ($i div 2**42) == ($i +> 42) ?? 'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5: OUTPUT: «bad␤»
<TimToady> loks like a bug
<TimToady> at the 32-bit boundary
<TimToady> m: my $i = -0x8000000000000000; say ($i +> 31)
<camelia> rakudo-moar 6bb1b5: OUTPUT: «-4294967296␤»
<TimToady> m: my $i = -0x8000000000000000; say ($i +> 32)
<camelia> rakudo-moar 6bb1b5: OUTPUT: «-1␤»
<TimToady> please report bug

RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.3k
On Tue, 09 May 2017 09:49:37 -0700, curt@tilmes.org wrote: Show quoted text
> <curt_> m: my $i = -0x8000000000000000; say ($i div 2**12) == ($i +> 12) ?? > 'good' !! 'bad'; > <camelia> rakudo-moar 6bb1b5: OUTPUT: «good␤» > <curt_> m: my $i = -0x8000000000000000; say ($i div 2**37) == ($i +> 37) ?? > 'good' !! 'bad'; > <camelia> rakudo-moar 6bb1b5: OUTPUT: «bad␤» > <curt_> m: my $i = -0x8000000000000000; say ($i div 2**23) == ($i +> 23) ?? > 'good' !! 'bad'; > <camelia> rakudo-moar 6bb1b5: OUTPUT: «good␤» > <curt_> m: my $i = -0x8000000000000000; say ($i div 2**42) == ($i +> 42) ?? > 'good' !! 'bad'; > <camelia> rakudo-moar 6bb1b5: OUTPUT: «bad␤» > <TimToady> loks like a bug > <TimToady> at the 32-bit boundary > <TimToady> m: my $i = -0x8000000000000000; say ($i +> 31) > <camelia> rakudo-moar 6bb1b5: OUTPUT: «-4294967296␤» > <TimToady> m: my $i = -0x8000000000000000; say ($i +> 32) > <camelia> rakudo-moar 6bb1b5: OUTPUT: «-1␤» > <TimToady> please report bug
Looking at the source code, this behaviour is due to a kludge to fix RT#126942[^1], according to which long bit shifts of negative integers should always produce -1 I'm not sure where the value of 32 bits came into play, other than it's the value where RT#126942's bug came around. [1] https://rt.perl.org/Ticket/Display.html?id=126942 [2] https://github.com/rakudo/rakudo/blob/6435933/src/core/Int.pm#L412
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 171b
Found where the problem was. Sent a PR[^1] to MoarVM to fix it and will commit Rakudo's patch and tests once that's merged. [1] https://github.com/MoarVM/MoarVM/pull/593


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org