in reply to Re^2: Number too big to fit in integer
in thread Number too big to fit in integer

I get the same with 5.36.0 as I did with 5.26.1. Here's what I originally used to home in on the tipping point:

% /opt/v5.36.0/bin/perl -MMath::BigInt -wle '$z0 = Math::BigInt->new(2 +)**64; for my $i (0..12) { $zi = $z0 + 2**$i; $ni = "$zi"; $d = ($ni +== ~0) ? "same" : "differ"; print "$i: $d" }' 0: same 1: same 2: same 3: same 4: same 5: same 6: same 7: same 8: same 9: same 10: same 11: same 12: differ %

Using eval "$zi == ~0" to make it more like direct use gives me the same result.

Replies are listed 'Best First'.
Re^4: Number too big to fit in integer
by syphilis (Archbishop) on Jan 01, 2023 at 02:00 UTC
    I get the same with 5.36.0 as I did with 5.26.1.

    Oh, I see. You were adding powers of 2 to the original value of 2**64.
    I get the same as you when I run the code you provided.

    I was incrementing by one:
    D:\>perl -MMath::BigInt -wle "$x = Math::BigInt->new(~0); $x++; while( +\"$x\" == ~0){$x++}; print $x;" 18446744073709553665
    Of course, this particular perl configuration sees 18446744073709553665 and 18446744073709554600 as the same value, anyway:
    D:\>perl -le "print 'ok' if 18446744073709553665 == 184467440737095546 +00;" ok
    However, that your 5.26.1 regards 18446744073709554600 and 18446744073709554599 as different values is a bug in 5.26.1. (I see the same bug in my Windows build of 5.26.0.)
    I believe that perl should regard those two values as equivalent for all IV and NV configurations.
    D:\>perl -wle "print 'ok' if 18446744073709554600 == 18446744073709554 +599;" ok
    For me, that fails to output 'ok' on 5.26.0. (If 5.26.0 has been built with -Duselongdouble, then 5.26.0 does get it right and outputs 'ok'.)

    Cheers,
    Rob

      Ok, there has been a change somewhere along the line: if I compare "n more than ~0" against "~0" for integer n, up to 5.28 it first compares different for n = 2985 (ie with 18446744073709554600); with 5.30 and later it first compares different for n = 2050 (ie with 18446744073709553665):

      % /opt/v5.28.1/bin/perl -MMath::BigInt -we '$z0 = Math::BigInt->new(~0 +); for (1..4096) { $z1 = $z0 + $_; $n1 = "$z1"; die $_ if $n1 != ~0 } +' 2985 at -e line 1. % /opt/v5.30.0-d/bin/perl -MMath::BigInt -we '$z0 = Math::BigInt->new( +~0); for (1..4096) { $z1 = $z0 + $_; $n1 = "$z1"; die $_ if $n1 != ~0 + }' 2050 at -e line 1. %

      (From the naming I know that's a v5.30.0 built with debugging, but that shouldn't make a difference here.)

        Ok, there has been a change somewhere along the line:

        Yes - beginning with perl-5.30.0, perl uses C's strtod() to assign values, instead of its own (buggy) atof routine that it had previously been using.
        That fixed many errors in assignment - eg https://github.com/Perl/perl5/issues/8730, which had been reported in Jan 2007.

        Cheers,
        Rob