New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bit overshift undefined: 1<<32 can be 1 #450
Comments
From @jhiOne of Jon's quiz show questions (print (1<<(1<<5))) and the offered $ perl -le 'print (1<<32)' This is what happens for example in Intel Linux with Perl 5.005_03, My guess is that the C standard doesn't actually say what should happen. Now, the question is: should we mandate a Known Behaviour for Here's something you can play with to see what your C compiler #include <stdio.h> Perl Info
|
From @jhiJarkko Hietaniemi writes:
All this guessing and recollecting (*) is so touching. Somebody on (*) "the second argument is interpreted modulo the wordsize [in bits] -- |
From [Unknown Contact. See original ticket]On Sun, 29 Aug 1999 00:26:59 +0300 (EET DST), Jarkko Hietaniemi
Here's what I get from VC++ on WinNT: ./shift The docs say:
-Jan |
From [Unknown Contact. See original ticket]
The wrapping is certainly, um, interesting. In C, we have this: main() { Which is what we have in Perl: for ($i = 30; $i < 35; $i++) { Note that changing %u to %d in both cases produces the negative -2147483648. Python does this: for i in xrange(30,35): But a simple change from 1 to 1L (built-in C-fast bigint) plus the printf for i in xrange(30,35): Trying to do the same in Perl gets you in trouble: % perl -MMath::BigInt=:constant -le 'print 1 << 40' --tom |
From [Unknown Contact. See original ticket]Oh, I can get it in C, too: main() { Gives me: 1 << 30 == 1073741824 Of course, leftshift of 80 bits doesn't work quite so well in C as in Python. :-) --tom |
From @jhiJarkko Hietaniemi writes:
After some testing: only AIX (both in ppc and power2) gets 0 from So what should it be: 0, 1, (NV)4294967296.0 (yech), or a bigint The same issue goes for right shift: 0 or modulo if overshifting? -- |
From @jhiKurt D. Starsinic writes:
Would that be B<undefined> or <EMPHASIS/>undefined</EMPHASIS> or <BLINK><HONK><FONT SIZE="big" COLOR="red">undefined</FONT></BLINK> (ducking) -- |
From [Unknown Contact. See original ticket]On Sun, Aug 29, 1999 at 01:18:02AM +0300, Jarkko Hietaniemi wrote:
Irix 6.5 on the O2 also gets 1.
My vote is not the NV under any circumstances, bigint preferred
In this case, 0 makes sense to me. Peace, |
Migrated from rt.perl.org#1291 (status was 'resolved')
Searchable as RT1291$
The text was updated successfully, but these errors were encountered: