mirror of
https://github.com/fastfloat/fast_float.git
synced 2026-06-15 08:26:08 +08:00
The previous commit detects multi-wrap u64 overflow at the max_digits
boundary by re-parsing the digits through a checked multiply-add loop
(O(max_digits)). Replace that with the constant-time check used in
simdjson: the leading digit plus a single threshold comparison.
For a max_digits-length value, min_safe_u64(base) == base^(max_digits-1)
is the smallest such value and also the width of each leading-digit band
[d*ms, (d+1)*ms). Since that width is < 2^64, the only band that can
straddle 2^64 is d == dmax (the largest leading digit that still fits),
and there it straddles at most once, so a single threshold dmax*ms
separates wrapped from non-wrapped values. A leading digit above dmax
always overflows; below dmax always fits. dmax and the threshold derive
from the existing min_safe_u64 table, so no new tables are needed and
dmax*ms cannot itself overflow.
Add a programmatic, self-verifying test for parse_int_string overflow
detection covering bases 2..36, complementing the hand-picked strings
added earlier. Every generated input is cross-checked against an
independent trusted oracle (a plain 64-bit checked multiply-add); on
success the parsed value is also compared exactly and full consumption
of the input is asserted.
Per base it exercises:
- an exact-boundary sweep of the 64 values straddling 2^64
(UINT64_MAX-31 .. 2^64+31), built by walking the digit string;
- UINT64_MAX, 2^64 and the all-max-digit value, each also with
leading zeros;
- random max_digits-length values across every leading digit, with
the heaviest sampling on the lead == dmax band that straddles 2^64,
and full coverage of lead > dmax (the multi-wrap region the naive
min_safe check accepted by mistake);
- max_digits-1 (never overflows) and max_digits+1 (always overflows).
A small signed (int64_t) section checks the exact INT64_MIN/INT64_MAX
limits round-trip and that INT64_MAX+1 / INT64_MIN-1 are rejected in
every base.
|
||
|---|---|---|
| .. | ||
| bloat_analysis | ||
| build_tests | ||
| installation_tests | ||
| basictest.cpp | ||
| BUILD.bazel | ||
| CMakeLists.txt | ||
| example_comma_test.cpp | ||
| example_integer_times_pow10.cpp | ||
| example_test.cpp | ||
| exhaustive32_64.cpp | ||
| exhaustive32_midpoint.cpp | ||
| exhaustive32.cpp | ||
| fast_int.cpp | ||
| fixedwidthtest.cpp | ||
| fortran.cpp | ||
| ipv4_test.cpp | ||
| json_fmt.cpp | ||
| long_exhaustive32_64.cpp | ||
| long_exhaustive32.cpp | ||
| long_random64.cpp | ||
| long_test.cpp | ||
| p2497.cpp | ||
| powersoffive_hardround.cpp | ||
| random64.cpp | ||
| random_string.cpp | ||
| rcppfastfloat_test.cpp | ||
| short_random_string.cpp | ||
| string_test.cpp | ||
| supported_chars_test.cpp | ||
| wide_char_test.cpp | ||