I would try to test the OP's problem that predecessor or successor are identical in numerical comparison.

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

Update

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.