Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: Largest integer in 64-bit perl

by syphilis (Archbishop)
on May 19, 2025 at 04:09 UTC ( [id://11165061]=note: print w/replies, xml ) Need Help??


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

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

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:
D:\>perl -MDevel::Peek -we "Dump (2**62); Dump ((2**62) + 1); Dump ((2 +**62) - 1);" SV = NV(0x1d26f8d3f20) at 0x1d26f8d3f38 REFCNT = 1 FLAGS = (PADTMP,NOK,READONLY,PROTECT,pNOK) NV = 4.6116860184273879e+18 SV = NV(0x1d26f8dbb88) at 0x1d26f8dbba0 REFCNT = 1 FLAGS = (PADTMP,NOK,READONLY,PROTECT,pNOK) NV = 4.6116860184273879e+18 SV = NV(0x1d26f8d4ac0) at 0x1d26f8d4ad8 REFCNT = 1 FLAGS = (PADTMP,NOK,READONLY,PROTECT,pNOK) NV = 4.6116860184273879e+18 D:\>perl -MDevel::Peek -we "Dump (1<<62); Dump ((1<<62) + 1); Dump ((1 +<<62) - 1);" SV = IV(0x132ea044988) at 0x132ea044998 REFCNT = 1 FLAGS = (PADTMP,IOK,READONLY,PROTECT,pIOK) IV = 4611686018427387904 SV = IV(0x132ea0449e8) at 0x132ea0449f8 REFCNT = 1 FLAGS = (PADTMP,IOK,READONLY,PROTECT,pIOK) IV = 4611686018427387905 SV = IV(0x132ea0442c8) at 0x132ea0442d8 REFCNT = 1 FLAGS = (PADTMP,IOK,READONLY,PROTECT,pIOK) IV = 4611686018427387903
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

Replies are listed 'Best First'.
Re^5: Largest integer in 64-bit perl
by LanX (Saint) on May 19, 2025 at 10:01 UTC
    > the power operator (**) always returns an NV

    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
    (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://11165061]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2025-06-21 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.