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

Interestingly, the "use integer" line did absolutely nothing for me on 32-bit Windows XP TinyPerl 5.8. I tried to run it on Linux with 64-bit Perl 5.36, and to my surprise, it didn't even run! :-O It produced no error message and no output at all. The program does have a for loop in it, but it looked like it didn't even start the loop. I don't understand... Here's the program again:

#!/usr/bin/perl use strict; use warnings; use integer; $| = 1; my $MAXQUAD = 18446744073709551615; for (my $i = 9007199254740000; $i <= $MAXQUAD; $i++) { printf("\n %.0f %d", $i, $i); }

So, anyway, I did notice that if I remove the "use integer" line, then the program runs. In fact, if I started the loop at, let's say, 4611686018420000000, then it will keep counting on the 64-bit Perl in Linux. Interesting!

However, when I stop the program by pressing CTRL+C, I notice something else. When printing the number $i as float, it sort of loses precision, but when printing it as %d number, it prints it precisely. In TinyPerl, I had the opposite experience with this where %f printed more precise values than %d. This is so weird... :P

4611686018420022272 4611686018420022338 4611686018420022272 4611686018420022339 4611686018420022272 4611686018420022340 4611686018420022272 4611686018420022341 4611686018420022272 4611686018420022342 4611686018420022272 4611686018420022343 4611686018420022272 4611686018420022344 4611686018420022272 4611686018420022345 4611686018420022272 4611686018420022346 4611686018420022272 4611686018420022347 4611686018420022272 4611686018420022348 4611686018420022272 4611686018420022349 4611686018420022272 4611686018420022350

Replies are listed 'Best First'.
Re^3: Largest integer in 64-bit perl
by pfaut (Priest) on May 17, 2025 at 00:34 UTC

    Try printing $MAXQUAD. I bet you get '-1'. That's why your code looks like it doesn't run.

    Update: I tried this and it prints the set value. However, I wonder if perl is treating it as a signed value when comparing it to $i because the loop never executes.

    90% of every Perl application is already written.
    dragonchild