in reply to Re^6: Largest integer in 64-bit perl
in thread Largest integer in 64-bit perl

The most sensible approach is to break out bigint/bigrat when it is needed. It's a scripting language, afterall, where we didn't get to declare the types. Python does it, and what would have been Perl 6 did it. I think it would be quite sensible for someone to come up with a new Perl 5 feature flag called use experimental "rational_math"; and bundle a copy of GMP with perl (or Tom-math or something) and have perl seamlessly support rational numbers. It would be much more "normal" than asking for "please give me a semi-arbitrary circumstantial mixture of double and int64_t".

Of course, that's a huge amount of work to specify and implement and write tests for, so I don't expect it to happen. But it would have saved me an awful lot of grief with rounding problems related to money over the years.

Replies are listed 'Best First'.
Re^8: Largest integer in 64-bit perl
by hippo (Archbishop) on May 30, 2025 at 18:58 UTC
    It would be much more "normal"

    The great thing about "normal" is that it means completely different things to different people. In this case, DWIM is "give me something close enough to what I want" and if you're after something exact in number theory terms you probably/should know the incantation for subverting/upgrading this. IMVHO.


    🦛

Re^8: Largest integer in 64-bit perl (UPDATED)
by LanX (Saint) on May 30, 2025 at 19:58 UTC
    > The most sensible approach is to break out bigint/bigrat when it is needed. ... Python does it

    Really? That's surprising me a bit... can you provide evidence for this?

    From my experience is Python "more" typed than Perl, leading to 3/2==1 because it assumes that's an integer operation only.

    edit
    OK, looks good in Python3, seems they also fixed the division issue from Python2
    :~$ python3 Python 3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 3/2 1.5 >>> (2**4711+1)-2**4711 1 >>>

    update

    LOL, I suppose nobody is perfect...

    >>> (2**(128/2)+1)-2**64 0.0 >>> (2**(64)+1)-2**64 1 >>> (2**(128//2)+1)-2**64 1 >>>

    Seems like 128/2 being a float, breaks the workaround xD

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery