in reply to Re: Largest integer in 64-bit perl
in thread Largest integer in 64-bit perl
How would you use a binary search to find the first gap?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Largest integer in 64-bit perl
by LanX (Saint) on May 18, 2025 at 11:56 UTC | |
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.
YMMV...
Cheers Rolf
UpdateIn 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. | [reply] [d/l] [select] |
by syphilis (Archbishop) on May 19, 2025 at 04:09 UTC | |
I haven't looked too closely, but I suspect that the fact that the power operator (**) always returns an NV might be causing problems. You might be better off using the << operator: The first one-liner results in 3 identical values; the second one-liner results in 3 different values. It's all just part of the fun we have when we use the utterly insane perl configuration where IV precision is greater than NV precision ;-) Cheers, Rob | [reply] [d/l] [select] |
by LanX (Saint) on May 19, 2025 at 10:01 UTC | |
sure that's why I said we must stay in the "realm of integers" for a proper binary search. I'm not sure about the "always" tho > You might be better off using the << operator: That's the classic approach, but I would choose a "pure" algorithm using + only, to find the point where adding two integers creates a non-integer.
Cheers Rolf
| [reply] [d/l] |