in reply to Perl's bad at arithmetic?

perlop says

Note that both << and >> in Perl are implemented directly using << and >> in C
[...]
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.
Not Perl's fault indeed.

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

    But my shift value should be 19, 36 and 69 and I'm using a 64-bit perl, so, at worst, I should be having problems only with the last one.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

      I don't see anything wrong with the first two. Your output is actually the same as the expectations you provided.

        You're right! (See for my lack of an excuse!) Night all!


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked