in reply to Re: unpacking unsigned long longs
in thread unpacking unsigned long longs

Also: is there an easy way to tell if I have perl compiled to support numbers that large?

Replies are listed 'Best First'.
Re^3: unpacking unsigned long longs
by ikegami (Patriarch) on Jul 06, 2009 at 16:12 UTC

    The necessary info is in Config.

    $ perl -MConfig -le'print $Config{ivsize}' 4

    You can see that value in perl -V as well.

    Of course, you could just try unpack 'Q'.

    $ perl -le'unpack "Q", chr(0)x8; print "ok"' Invalid type 'Q' in unpack at -e line 1.
      I take it ivsize==4 is good for what I want?

        Sorry. Like mine, your Perl uses 32-bit integers (8 bits/byte * 4 byte = 32 bits). It can't hold a 64-bit number (64 bits / 8 bits/byte = 8 bytes) unless you use something like Math::BigInt. You won't be able to use unpack 'Q'.

        Tell me which cell of my table you want, and I'll provide some code to do the same thing.

      Alright, so I tried unpacking Q (and q) to no avail. But perl didn't spit out any errors when I try to assign 2^45 to a variable and then print it. Does that still mean perl isn't compiled to support 64 bit numbers? If so, how can I go about fixing this?

        Did you really mean 2^45 (47) or 2**45 (35184372088832).

        A double-precision floating point number can handle numbers much bigger than 2**45. And with 53 bits of precision, it can represent 2**45 faithfully.

        If so, how can I go about fixing this?

        See the "64 bit support" section in the perl distribution's INSTALL file for how to build such a perl.

        Or like I said already, tell me which cell of my table you want, and I'll provide some code to do the same thing on a 32-bit build of Perl.