use v5.12; use warnings; #say "Mode: ", my $mode = $ARGV[0] // 0; use Config; say $Config{ivsize}; say $Config{nvsize}; sub test { my ($mode) = @_; say "**** Mode: $mode"; my $now=1; for my $x ( 1.. 65) { $now = $mode == 0 ? 2 * $now : $mode == 1 ? 2 ** $x : $mode == 2 ? 2 ** $x -1 : die "Mode=$mode not implemented yet"; if ( $now == $now-1 or $now == $now+1 ) { print "Problem at $now = 2**$x\n"; printf "%22u %22u %22u\n",$now-1,$now,$now+1; last; } } } test($_) for 0..2;
this will break at 2**64 when I stay purely integer
NB: I didn't implement the full binary search, since there is no backtracking yet
But I'm getting weird conversion results when leaving the realm of integer (see the "modes"), these are most likely side-effects of starting with a float (or bugs). Probably better to use Hex-strings.
perl /home/lanx/perl/pm/integer-gap.pl 8 8 **** Mode: 0 Problem at 1.84467440737096e+19 = 2**64 18446744073709551615 18446744073709551615 18446744073709551615 **** Mode: 1 Problem at 9.00719925474099e+15 = 2**53 9007199254740991 9007199254740992 9007199254740993 **** Mode: 2 Problem at 4.61168601842739e+18 = 2**62 4611686018427387904 4611686018427387904 4611686018427387904
YMMV...
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
In hindsight, the cleanest approach would be to only rely on addition and substraction of integers. No multiplications or exponentions (which might be implemented as approximation)
Since the last safe interval is guaranteed to be an integer too.
In reply to Re^3: Largest integer in 64-bit perl
by LanX
in thread Largest integer in 64-bit perl
by harangzsolt33
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |