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