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

.... but floats aren't promoted to integers.

It can get a bit moot:
D:\>perl -MDevel::Peek -le "$x = (2 ** 53) - 1; Dump $x; $x++; Dump $x +; $x++; Dump $x; $x++; Dump $x;" SV = NV(0x28e88c5a2f8) at 0x28e88c5a310 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 9007199254740991 SV = PVNV(0x28e88c24e10) at 0x28e88c5a310 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 9007199254740992 NV = 9007199254740991 PV = 0 SV = PVNV(0x28e88c24e10) at 0x28e88c5a310 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 9007199254740993 NV = 9007199254740991 PV = 0 SV = PVNV(0x28e88c24e10) at 0x28e88c5a310 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 9007199254740994 NV = 9007199254740991 PV = 0
The fact that the flags change from (NOK,pNOK) to (IOK,pIOK) suggests to me that the NV has been promoted to an IV.
Or does the fact that both the IV and NV slots have been filled suggest that it's neither an IV nor an NV. Or maybe that suggests that it's both ? ... I don't know.

Anyway, I'm not looking for an argument. It's just one of those things that I find a little mysterious.

Other differences between floats and ints is the existence of inifinity, NaN and -0

One of my beefs with Math::BigInt is that it has a NaN and an inf:
D:\>perl -MMath::BigInt -le "$x = Math::BigInt->new(2.3); print $x; pr +int ref($x);" NaN Math::BigInt D:\>perl -MMath::BigInt -le "$x = Math::BigInt->new(1) / 0; print $x; +print ref($x);" inf Math::BigInt
I don't regard it as all that important, but it probably shouldn't do that.
I couldn't quickly get it to provide a "-0", but I did get the following weirdness:
D:\>perl -MMath::BigInt -le "$x = Math::BigInt->new(1) / inf; print $x +; print ref($x);" 0 Math::BigInt D:\>perl -MMath::BigInt -le "$x = Math::BigInt->new(1) / -inf; print $ +x; print ref($x);" -1 Math::BigInt
Cheers,
Rob

Replies are listed 'Best First'.
Re^6: Largest integer in 64-bit perl
by ikegami (Patriarch) on May 27, 2025 at 20:04 UTC

    When the pre-increment operator is provided an integer that less than its max, it just adds one to it. Otherwise, it calls crazy, 150-lines long sv_inc. And yeah, sv_inc can promote to integer. Woops.

Re^6: Largest integer in 64-bit perl
by cavac (Prior) on Jun 02, 2025 at 14:49 UTC

    Out of pure curiosity: What are you all working on that requires integers bigger than 64 bit? So far, the only cases i could think of are things like black holes and possibly simulating nuclear explosions down to subatomic particles.

    (I'm working mostly with boring financial data. If 64 bit is ever insufficient, something inflationary has probably gone very, very wrong. Or my software is used in Zimbabwe. Same thing, really...)

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
    Also check out my sisters artwork and my weekly webcomics
Re^6: Largest integer in 64-bit perl
by ikegami (Patriarch) on Jun 02, 2025 at 15:44 UTC

    I couldn't quickly get it to provide a "-0"

    $ perl -e'$_ = -1; $_ /= 10 while $_ < 0; printf "%g\n", $_;' -0