in reply to Perl's bad at arithmetic?
perlop says
Note that both << and >> in Perl are implemented directly using << and >> in CNot Perl's fault indeed.
[...]
The result of overflowing the range of the integers is undefined because it is undefined also in C. In other words, using 32-bit integers, 1 << 32 is undefined. Shifting by a negative number of bits is also undefined.
perl -E 'say unpack "b*", pack "Q", ( 3<<$_ ) for 60..70;' 0000000000000000000000000000000000000000000000000000000000001100 0000000000000000000000000000000000000000000000000000000000000110 0000000000000000000000000000000000000000000000000000000000000011 0000000000000000000000000000000000000000000000000000000000000001 1100000000000000000000000000000000000000000000000000000000000000 0110000000000000000000000000000000000000000000000000000000000000 0011000000000000000000000000000000000000000000000000000000000000 0001100000000000000000000000000000000000000000000000000000000000 0000110000000000000000000000000000000000000000000000000000000000 0000011000000000000000000000000000000000000000000000000000000000 0000001100000000000000000000000000000000000000000000000000000000
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl's bad at arithmetic?
by BrowserUk (Patriarch) on Mar 27, 2015 at 23:37 UTC | |
by Eily (Monsignor) on Mar 28, 2015 at 00:00 UTC | |
by BrowserUk (Patriarch) on Mar 28, 2015 at 00:11 UTC |