in reply to Re^5: use64bitint in building Perl
in thread use64bitint in building Perl

Since I can't think of any variables in my web site that need > 32 bits, your reply has talked me out of building with use64bitint. Thank you for helping me with this decision.

cmac

Replies are listed 'Best First'.
Re^7: use64bitint in building Perl
by tilly (Archbishop) on Dec 30, 2008 at 01:16 UTC
    Furthermore note that if numbers do go over 2 GB, Perl automatically upgrades you to floats, which can represent integers precisely up to 52 bits or so. Don't put undue trust in this because some floating point routines may introduce rounding errors, and the number is not always displayed exactly, but still floating point is not immediately worse than integer arithmetic.
      if numbers do go over 2 GB, Perl automatically upgrades you to floats

      If perl has been built with use64bitint and without uselongdouble, the "upgrade" can happen before the 2GB limit is reached ... which is definitely not what you want (as it means you've lost precision):
      $ perl -MDevel::Peek -le 'Dump(17 + (2 ** 56))' SV = NV(0x10450940) at 0x10410fd0 REFCNT = 1 FLAGS = (PADBUSY,PADTMP,NOK,READONLY,pNOK) NV = 7.2057594037928e+16
      In this instance, the workaround is to 'use integer':
      $ perl -Minteger -MDevel::Peek -le 'Dump(17 + (2 ** 56))' SV = IV(0x10429358) at 0x10410fdc REFCNT = 1 FLAGS = (PADBUSY,PADTMP,IOK,READONLY,pIOK) IV = 72057594037927953
      Just a little trap for the unwary.

      Cheers,
      Rob

      Update: Ooops - where *I* wrote 2GB above, I should have written "64-bit". And my point is unrelated to tilly's, anyway ....

        Your code doesn't demonstrate what you claim for two reasons.

        • 2**56 is 33,554,432 times larger than 2GB (2**31).
        • You didn't show any loss of precision (even though there was some).
        Not so fast on losing precision. IEEE binary floating-point for double precision (which is what I believe Perl uses) represents small integers exactly. Where small is anything under 53 bits. So the upgrade wastes memory, but doesn't necessarily lose any precision.

        Your code doesn't demonstrate what you claim for two reasons.

        • 2**56 is 33,554,432 times larger than 2GB (2**31).
        • You didn't show any loss of precision (even though there was some).