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. For my system build (5.26.1 for Ubuntu) the first integer that gets stored as a double distinguishable from ~0 is 18446744073709554600 (which has actually been stored in NV as 2^64 + 2^12):
% perl -E 'say "ok" if 18446744073709554600 > ~0' ok % perl -E 'say "ok" if 18446744073709554599 > ~0' %
If that loss of precision is unacceptable for your use case, then you must avoid letting Perl do the string-to-number conversion for you. If you are writing pure Perl, Math::BigInt seems like a pretty reasonable way to sort that out. If you're writing XS code, you can call the C library's strtoul() or the perl API functions grok_number() or grok_number_flags().
In reply to Re: Number too big to fit in integer
by hv
in thread Number too big to fit in integer
by jpl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |