Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: Largest integer in 64-bit perl

by ikegami (Patriarch)
on Jun 01, 2025 at 10:10 UTC ( [id://11165189]=note: print w/replies, xml ) Need Help??


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

You'll have the same problems using doubles near 2**53 in another language. You'd have to use 64-bit ints to avoid that. Same in Perl. It doesn't hold.

Replies are listed 'Best First'.
Re^5: Largest integer in 64-bit perl
by BillKSmith (Monsignor) on Jun 02, 2025 at 04:24 UTC
    Here is a few examples of the same expression in strawberry perl 5.38.2 and in the gfortran packaged with it. I believe the fortran.
    use strict; use warnings; use integer; use feature 'say'; my $base = 3; my $power = 33; my $result = $base ** $power; printf "%d\n", $result; $power = 38; $result = $base ** $power; printf "%d\n", $result
    program fort integer*8 base, power integer*8 result base = 3 power = 33 result = base ** power +1; print *, result power = 38 result = base ** power +1; print *, result end program

    RESULTS

    C:\Users\Bill\forums\monks>perl power3.pl 5559060566555523 1350851717672992000 C:\Users\Bill\forums\monks>gfortran -o power3 power3.f90 C:\Users\Bill\forums\monks>power3.exe 5559060566555524 1350851717672992090
    Bill
      The first result is identical, you are adding 1 in Fortran only.

      The second one needs 61 bits and is outside float precision in Perl.

      Edit

      This shows the same result and that the exponentiation is the real "culprit".

      DB<11> $x=1; $x*=3 for 1..38; say $x 1350851717672992089 DB<12>

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2025-07-20 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.