in reply to Re: Number too big to fit in integer
in thread Number too big to fit in integer

That's tricky: for a number that doesn't fit in UV (integer), Perl automatically stores it in NV (double) which can result in an immediate loss of precision.

See also $Config{nv_overflows_integers_at}:

$ uname -p x86_64 $ perl -MConfig -le 'print eval $Config{nv_overflows_integers_at}' 9007199254740992

Replies are listed 'Best First'.
Re^3: Number too big to fit in integer
by jpl (Monk) on Dec 25, 2022 at 17:10 UTC

    I kinda like that, but eval frankly creeps me out a bit.

      Upon further reflection, $Config{nv_overflows_integers_at} doesn't tell me anything I didn't know. It still doesn't give me something I can use to determine if an argument that looks like an integer will fit in an integer. I will give it credit for obscurity, though:-)

      DB<1> use Config DB<2> say $Config{nv_overflows_integers_at} 256.0*256.0*256.0*256.0*256.0*256.0*2.0*2.0*2.0*2.0*2.0

      If I eval it, I get something that is, pretty much by definition, something that won't fit in an integer. But, as we have seen, if I compare it using > to ~0, a valid integer, it may not compare high.