Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Number too big to fit in integer

by syphilis (Archbishop)
on Jan 01, 2023 at 02:00 UTC ( [id://11149243]=note: print w/replies, xml ) Need Help??


in reply to Re^3: 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.

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

Replies are listed 'Best First'.
Re^5: Number too big to fit in integer
by hv (Prior) on Jan 01, 2023 at 04:27 UTC

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11149243]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found