in reply to 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. 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().
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Number too big to fit in integer
by haukex (Archbishop) on Dec 25, 2022 at 07:53 UTC | |
by jpl (Monk) on Dec 25, 2022 at 17:10 UTC | |
by jpl (Monk) on Dec 26, 2022 at 16:59 UTC | |
|
Re^2: Number too big to fit in integer
by syphilis (Archbishop) on Dec 31, 2022 at 13:05 UTC | |
by hv (Prior) on Dec 31, 2022 at 21:57 UTC | |
by syphilis (Archbishop) on Jan 01, 2023 at 02:00 UTC | |
by hv (Prior) on Jan 01, 2023 at 04:27 UTC | |
by syphilis (Archbishop) on Jan 01, 2023 at 09:40 UTC | |
|
Re^2: Number too big to fit in integer
by jpl (Monk) on Dec 25, 2022 at 00:54 UTC | |
by NERDVANA (Priest) on Dec 25, 2022 at 05:49 UTC |