Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Difference between Perl and Java for << operator?

by GrandFather (Saint)
on Jul 30, 2021 at 03:58 UTC ( [id://11135510]=note: print w/replies, xml ) Need Help??


in reply to Difference between Perl and Java for << operator?

-268435456 implies the JavaScript interpreter is using signed 32 bit numbers. The 4026531840 result implies Perl is representing the value as a 32 bit unsigned number.

0xFFFFFFFF is a 32 bit value. If you shift it left by 28 bits you need 32 + 28 = 60 bits to represent the number so neither answer is actually correct in the sense that the true arithmetic result is given.

With Perl you have the option of building perl (the interpreter) yourself and setting parameters like the size of various numeric types. An out of the box 64 bit Perl will use 64 bit integer variables and would give the correct result in this case.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
  • Comment on Re: Difference between Perl and Java for << operator?

Replies are listed 'Best First'.
Re^2: Difference between Perl and Java for << operator?
by syphilis (Archbishop) on Jul 30, 2021 at 04:58 UTC
    An out of the box 64 bit Perl will use 64 bit integer variables and would give the correct result in this case

    An interesting aside is that, for the OP's purposes, perl's ivsize is irrelevant, and this can be demonstrated using jwkrahn's perceptive solution :

    With 64-bit IVs:
    >perl -V:ivsize ivsize='8'; >perl -le "print unpack 'l', pack 'l', 0xFFFFFFFF << 28;" -268435456
    and with 32-bit IVs:
    C:\>perl -V:ivsize ivsize='4'; C:\>perl -le "print unpack 'l', pack 'l', 0xFFFFFFFF << 28;" -268435456
    Nor does $Config{longsize} make a difference - because the "l" template always specifies 32-bit.
    I believe the "i" template could also be used.
    According to the documentation, the "i" template could be specifying either 32-bit or 64-bit, depending upon $Config{intsize} - but I've never struck a perl where $Config{intsize} != 4.

    Cheers,
    Rob
Re^2: Difference between Perl and Java for << operator?
by The Perlman (Scribe) on Jul 30, 2021 at 07:44 UTC
    "implies the JavaScript interpreter"

    Java, not Javascript!

    - Ron

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11135510]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-18 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found