Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^5: Largest integer in 64-bit perl

by BillKSmith (Monsignor)
on Jun 02, 2025 at 04:24 UTC ( [id://11165198]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2026-04-19 23:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.