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

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

Replies are listed 'Best First'.
Re^6: Largest integer in 64-bit perl
by LanX (Saint) on Jun 02, 2025 at 06:30 UTC
    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