From 308e266a90ca68a8727add755a1883df47cf6428 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Fri, 31 Jul 2026 19:28:24 +0000 Subject: [PATCH 1/2] Add trailing zero fallback benchmark and tests Measure the digit comparison fallback directly --- CMakeLists.txt | 11 ++ benchmarks/trailing_zero_benchmark.cpp | 252 +++++++++++++++++++++++++ tests/BUILD.bazel | 9 + tests/CMakeLists.txt | 1 + tests/trailing_zeros_test.cpp | 164 ++++++++++++++++ 5 files changed, 437 insertions(+) create mode 100644 benchmarks/trailing_zero_benchmark.cpp create mode 100644 tests/trailing_zeros_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ec61423..69fdf76d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,17 @@ target_include_directories( $ ) target_compile_features(fast_float INTERFACE cxx_std_11) + +# This focused benchmark has no external dependencies, so it can be built +# independently of the data-driven benchmark suite below. +option(FASTFLOAT_TRAILING_ZERO_BENCHMARK + "Build the trailing decimal zero slow-path benchmark" OFF) +if(FASTFLOAT_TRAILING_ZERO_BENCHMARK) + add_executable(trailing_zero_benchmark benchmarks/trailing_zero_benchmark.cpp) + target_link_libraries(trailing_zero_benchmark PRIVATE fast_float) + target_compile_features(trailing_zero_benchmark PRIVATE cxx_std_11) +endif() + if(FASTFLOAT_SANITIZE) target_compile_options(fast_float INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) target_link_libraries(fast_float INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) diff --git a/benchmarks/trailing_zero_benchmark.cpp b/benchmarks/trailing_zero_benchmark.cpp new file mode 100644 index 00000000..8285e7cb --- /dev/null +++ b/benchmarks/trailing_zero_benchmark.cpp @@ -0,0 +1,252 @@ +#include "fast_float/fast_float.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +struct input_case { + std::string input; + std::string canonical; +}; + +struct target_case { + fast_float::parsed_number_string number; + fast_float::adjusted_mantissa am; + + target_case() : number(), am() {} +}; + +volatile uint64_t sink = 0; + +std::string nonzero_tail(size_t length) { + std::string result(length, '1'); + result.front() = '7'; + result.back() = '7'; + return result; +} + +bool make_target_case(std::string const &input, target_case &target) { + fast_float::parse_options options; + fast_float::parsed_number_string const parsed = + fast_float::parse_number_string( + input.data(), input.data() + input.size(), options, true); + fast_float::adjusted_mantissa am = + fast_float::compute_float>( + parsed.exponent, parsed.mantissa); + if (!parsed.valid || !parsed.too_many_digits || am.power2 < 0 || + am == fast_float::compute_float>( + parsed.exponent, parsed.mantissa + 1)) { + return false; + } + am = fast_float::compute_error>( + parsed.exponent, parsed.mantissa); + if (am.power2 >= 0) { + return false; + } + target.number = parsed; + target.am = am; + return true; +} + +bool takes_digit_comp(std::string const &input) { + target_case target; + return make_target_case(input, target); +} + +uint64_t bits(double value) { + uint64_t result; + ::memcpy(&result, &value, sizeof(result)); + return result; +} + +void parse(std::string const &input, double &value, std::errc &error, + size_t &parsed_length) { + fast_float::from_chars_result const result = fast_float::from_chars( + input.data(), input.data() + input.size(), value); + error = result.ec; + parsed_length = size_t(result.ptr - input.data()); +} + +bool verify_case(input_case const &test) { + double input_value = 0; + double canonical_value = 0; + std::errc input_error; + std::errc canonical_error; + size_t input_length = 0; + size_t canonical_length = 0; + parse(test.input, input_value, input_error, input_length); + parse(test.canonical, canonical_value, canonical_error, canonical_length); + return takes_digit_comp(test.input) && + input_length + 1 == test.input.size() && + canonical_length + 1 == test.canonical.size() && + input_error == canonical_error && + bits(input_value) == bits(canonical_value); +} + +std::vector make_cases(std::vector const &zero_counts) { + // This prefix makes compute_float(m) and compute_float(m + 1) differ at + // exponent -18, so public from_chars reaches digit_comp after parsing a + // coefficient longer than 19 digits. + std::string const prefix = "6497987825129815764"; + std::vector result; + for (size_t core_length : {size_t(20), size_t(30), size_t(120)}) { + std::string const tail = nonzero_tail(core_length - prefix.size()); + for (size_t zero_count : zero_counts) { + std::string const zeroes(zero_count, '0'); + std::string const integer_exponent = + std::to_string(-18 - int(tail.size()) - int(zero_count)); + + // Put a non-digit marker after each number so verification also checks + // the public from_chars pointer result. + result.push_back(input_case{prefix + tail + zeroes + "e" + + integer_exponent + "x", + prefix + tail + "e" + + std::to_string(-18 - int(tail.size())) + + "x"}); + result.push_back(input_case{"0." + prefix + tail + zeroes + "e1x", + "0." + prefix + tail + "e1x"}); + result.push_back(input_case{prefix.substr(0, 1) + "." + + prefix.substr(1) + tail + zeroes + "e0x", + prefix.substr(0, 1) + "." + + prefix.substr(1) + tail + "e0x"}); + } + } + return result; +} + +bool verify(std::vector const &cases) { + for (input_case const &test : cases) { + if (!verify_case(test)) { + return false; + } + } + return true; +} + +bool make_target_cases(std::vector const &cases, + std::vector &targets) { + targets.clear(); + targets.reserve(cases.size()); + for (input_case const &test : cases) { + target_case target; + if (!make_target_case(test.input, target)) { + return false; + } + targets.push_back(target); + } + return true; +} + +void parse_all(std::vector const &cases, size_t iterations) { + uint64_t local_sink = 0; + for (size_t iteration = 0; iteration < iterations; ++iteration) { + for (input_case const &test : cases) { + double value = 0; + std::errc error; + size_t parsed_length = 0; + parse(test.input, value, error, parsed_length); + local_sink += bits(value) + uint64_t(parsed_length) + uint64_t(error); + } + } + sink += local_sink; +} + +double benchmark(std::vector const &cases) { + // Keep input construction and correctness validation out of the measured + // parse operation, as callers normally own the input buffers already. + parse_all(cases, 1); + size_t const iterations = 2000; + std::chrono::steady_clock::time_point const start = + std::chrono::steady_clock::now(); + parse_all(cases, iterations); + std::chrono::steady_clock::duration const elapsed = + std::chrono::steady_clock::now() - start; + double const operations = double(cases.size()) * double(iterations); + return std::chrono::duration(elapsed).count() / + operations; +} + +void digit_comp_all(std::vector &targets, size_t iterations) { + uint64_t local_sink = 0; + for (size_t iteration = 0; iteration < iterations; ++iteration) { + for (target_case &target : targets) { + fast_float::adjusted_mantissa const answer = + fast_float::digit_comp(target.number, target.am); + local_sink += answer.mantissa + uint64_t(answer.power2); + } + } + sink += local_sink; +} + +double benchmark_digit_comp(std::vector &targets) { + digit_comp_all(targets, 1); + size_t const iterations = 20000; + std::chrono::steady_clock::time_point const start = + std::chrono::steady_clock::now(); + digit_comp_all(targets, iterations); + std::chrono::steady_clock::duration const elapsed = + std::chrono::steady_clock::now() - start; + double const operations = double(targets.size()) * double(iterations); + return std::chrono::duration(elapsed).count() / + operations; +} + +} // namespace + +int main(int argc, char **argv) { + if (argc != 2) { + std::cerr << "usage: trailing_zero_benchmark " + "--verify|--benchmark|--target-benchmark\n"; + return EXIT_FAILURE; + } + + std::string const mode(argv[1]); + if (mode == "--verify") { + std::vector const cases = make_cases( + {size_t(0), size_t(1), size_t(8), size_t(15), size_t(16), size_t(17), + size_t(64), size_t(700), size_t(769), size_t(1000), size_t(4096)}); + if (!verify(cases)) { + std::cerr << "trailing-zero verification failed\n"; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } + + if (mode == "--benchmark") { + std::vector const cases = make_cases( + {size_t(64), size_t(700), size_t(769), size_t(4096)}); + if (!verify(cases)) { + std::cerr << "trailing-zero verification failed\n"; + return EXIT_FAILURE; + } + std::cout << "{\"metric\":\"ns_per_parse\",\"value\":" + << std::fixed << std::setprecision(3) << benchmark(cases) + << "}\n"; + return EXIT_SUCCESS; + } + + if (mode == "--target-benchmark") { + std::vector const cases = make_cases( + {size_t(64), size_t(700), size_t(769), size_t(4096)}); + std::vector targets; + if (!verify(cases) || !make_target_cases(cases, targets)) { + std::cerr << "trailing-zero verification failed\n"; + return EXIT_FAILURE; + } + std::cout << "{\"metric\":\"ns_per_digit_comp\",\"value\":" + << std::fixed << std::setprecision(3) + << benchmark_digit_comp(targets) << "}\n"; + return EXIT_SUCCESS; + } + + std::cerr << "unknown mode: " << mode << '\n'; + return EXIT_FAILURE; +} diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index 57d8c342..10c99de9 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -70,6 +70,15 @@ cc_test( ], ) +cc_test( + name = "trailing_zeros_test", + srcs = ["trailing_zeros_test.cpp"], + deps = [ + "//:fast_float", + "@doctest//doctest", + ], +) + cc_test( name = "powersoffive_hardround", srcs = ["powersoffive_hardround.cpp"], diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 19f24529..e3935b20 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -80,6 +80,7 @@ if (FASTFLOAT_SUPPLEMENTAL_TESTS) endif() fast_float_add_cpp_test(p2497) fast_float_add_cpp_test(long_test) +fast_float_add_cpp_test(trailing_zeros_test) fast_float_add_cpp_test(powersoffive_hardround) fast_float_add_cpp_test(string_test) fast_float_add_cpp_test(fast_int) diff --git a/tests/trailing_zeros_test.cpp b/tests/trailing_zeros_test.cpp new file mode 100644 index 00000000..63a55efe --- /dev/null +++ b/tests/trailing_zeros_test.cpp @@ -0,0 +1,164 @@ +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "doctest/doctest.h" + +#include "fast_float/fast_float.h" + +#include +#include +#include +#include +#include + +namespace { + +struct parse_result { + uint64_t value_bits; + size_t parsed_length; + std::errc error; +}; + +std::string nonzero_tail(size_t length) { + std::string result(length, '1'); + result.front() = '7'; + result.back() = '7'; + return result; +} + +uint64_t bits(double value) { + uint64_t result; + ::memcpy(&result, &value, sizeof(result)); + return result; +} + +parse_result parse(std::string const &input) { + double value = 0; + fast_float::from_chars_result const result = fast_float::from_chars( + input.data(), input.data() + input.size(), value); + return parse_result{bits(value), size_t(result.ptr - input.data()), result.ec}; +} + +bool takes_digit_comp(std::string const &input) { + fast_float::parse_options options; + fast_float::parsed_number_string const parsed = + fast_float::parse_number_string( + input.data(), input.data() + input.size(), options, true); + fast_float::adjusted_mantissa am = + fast_float::compute_float>( + parsed.exponent, parsed.mantissa); + if (parsed.too_many_digits && am.power2 >= 0 && + am != fast_float::compute_float>( + parsed.exponent, parsed.mantissa + 1)) { + am = fast_float::compute_error>( + parsed.exponent, parsed.mantissa); + } + return parsed.valid && am.power2 < 0; +} + +void check_equivalent(std::string const &padded, std::string const &canonical) { + std::string const padded_with_marker = padded + "x"; + std::string const canonical_with_marker = canonical + "x"; + REQUIRE(takes_digit_comp(padded_with_marker)); + + parse_result const padded_result = parse(padded_with_marker); + parse_result const canonical_result = parse(canonical_with_marker); + CHECK(padded_result.parsed_length == padded.size()); + CHECK(canonical_result.parsed_length == canonical.size()); + CHECK(padded_result.error == canonical_result.error); + CHECK(padded_result.value_bits == canonical_result.value_bits); +} + +template std::basic_string widen(std::string const &input) { + return std::basic_string(input.begin(), input.end()); +} + +template parse_result parse_wide(std::string const &input) { + std::basic_string const wide = widen(input); + double value = 0; + fast_float::from_chars_result_t const result = fast_float::from_chars( + wide.data(), wide.data() + wide.size(), value); + return parse_result{bits(value), size_t(result.ptr - wide.data()), result.ec}; +} + +template +void check_equivalent_wide(std::string const &padded, + std::string const &canonical) { + std::string const padded_with_marker = padded + "x"; + std::string const canonical_with_marker = canonical + "x"; + parse_result const padded_result = parse_wide(padded_with_marker); + parse_result const canonical_result = parse_wide(canonical_with_marker); + CHECK(padded_result.parsed_length == padded.size()); + CHECK(canonical_result.parsed_length == canonical.size()); + CHECK(padded_result.error == canonical_result.error); + CHECK(padded_result.value_bits == canonical_result.value_bits); +} + +} // namespace + +TEST_CASE("long trailing zero coefficients preserve public from_chars results") { + // The prefix is an ambiguous 19-digit mantissa at exponent -18. Adding a + // twentieth digit makes public from_chars use the digit comparison fallback. + std::string const prefix = "6497987825129815764"; + std::vector const zero_counts = { + 0, 1, 8, 15, 16, 17, 64, 700, 769, 1000, 4096}; + for (size_t core_length : {size_t(20), size_t(30), size_t(120)}) { + std::string const tail = nonzero_tail(core_length - prefix.size()); + for (size_t zero_count : zero_counts) { + std::string const zeroes(zero_count, '0'); + std::string const integer_exponent = + std::to_string(-18 - int(tail.size()) - int(zero_count)); + + // Integer suffixes need a compensating explicit exponent. Fractional + // suffixes do not, because the decimal point already fixes their scale. + check_equivalent(prefix + tail + zeroes + "e" + integer_exponent, + prefix + tail + "e" + + std::to_string(-18 - int(tail.size()))); + check_equivalent("-" + prefix + tail + zeroes + "e" + integer_exponent, + "-" + prefix + tail + "e" + + std::to_string(-18 - int(tail.size()))); + check_equivalent("0." + prefix + tail + zeroes + "e1", + "0." + prefix + tail + "e1"); + check_equivalent(prefix.substr(0, 1) + "." + prefix.substr(1) + tail + + zeroes + "e0", + prefix.substr(0, 1) + "." + prefix.substr(1) + tail + + "e0"); + } + } +} + +TEST_CASE("trailing zero fallback accepts inputs without explicit exponents") { + // This prefix is ambiguous at exponent -19, which is the corrected exponent + // for a fraction-only input without an explicit exponent. + std::string const prefix = "2686910556586236953"; + for (size_t zero_count : + {size_t(0), size_t(15), size_t(16), size_t(700), size_t(4096)}) { + std::string const zeroes(zero_count, '0'); + check_equivalent("0." + prefix + "7" + zeroes, + "0." + prefix + "7"); + } +} + +TEST_CASE("trailing zero fallback supports wide character input") { + std::string const prefix = "6497987825129815764"; + std::string const tail = nonzero_tail(101); + std::string const zeroes(769, '0'); + std::string const padded = "0." + prefix + tail + zeroes + "e1"; + std::string const canonical = "0." + prefix + tail + "e1"; + check_equivalent_wide(padded, canonical); + check_equivalent_wide(padded, canonical); + check_equivalent_wide(padded, canonical); +} + +TEST_CASE("all-zero coefficients retain their public result") { + for (size_t zero_count : {size_t(0), size_t(16), size_t(700), size_t(4096)}) { + std::string const integer = "0" + std::string(zero_count, '0') + "e10x"; + std::string const fraction = "0." + std::string(zero_count, '0') + "e-10x"; + parse_result const integer_result = parse(integer); + parse_result const fraction_result = parse(fraction); + CHECK(integer_result.parsed_length + 1 == integer.size()); + CHECK(fraction_result.parsed_length + 1 == fraction.size()); + CHECK(integer_result.error == std::errc()); + CHECK(fraction_result.error == std::errc()); + CHECK(integer_result.value_bits == 0); + CHECK(fraction_result.value_bits == 0); + } +} From 52a1f4f15e972fa30c38be4dc27faca8c550c295 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Fri, 31 Jul 2026 19:39:16 +0000 Subject: [PATCH 2/2] Trim long trailing zero suffixes in digit comparison --- include/fast_float/digit_comparison.h | 86 ++++++++++++++++++++++++++- tests/trailing_zeros_test.cpp | 52 +++++++++++++++- 2 files changed, 134 insertions(+), 4 deletions(-) diff --git a/include/fast_float/digit_comparison.h b/include/fast_float/digit_comparison.h index c2c83b0c..5ec734bd 100644 --- a/include/fast_float/digit_comparison.h +++ b/include/fast_float/digit_comparison.h @@ -428,6 +428,82 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp( // `b` as a big-integer type, scaled to the same binary exponent as // the actual digits. we then compare the big integer representations // of both, and use that to direct rounding. +template +fastfloat_really_inline FASTFLOAT_CONSTEXPR20 bool +has_trailing_zero(parsed_number_string_t const &num) noexcept { + if (num.fraction.ptr != nullptr && num.fraction.len() != 0) { + return num.fraction[num.fraction.len() - 1] == UC('0'); + } + return num.integer.len() != 0 && + num.integer[num.integer.len() - 1] == UC('0'); +} + +// The long decimal fallback is only reached for an ambiguous conversion. For +// a sufficiently long zero suffix, scanning backward is cheaper than building +// zero limbs in the bigint. This helper leaves `last` at the final nonzero +// digit and returns the number of zeroes it removed. +template +fastfloat_really_inline FASTFLOAT_CONSTEXPR20 size_t +trim_zeros_from_end(UC const *first, UC const *&last) noexcept { + size_t zeroes = 0; + while (!cpp20_and_in_constexpr() && + std::distance(first, last) >= int_cmp_len()) { + uint64_t value; + ::memcpy(&value, last - int_cmp_len(), sizeof(uint64_t)); + if (value != int_cmp_zeros()) { + break; + } + last -= int_cmp_len(); + zeroes += size_t(int_cmp_len()); + } + while (last != first && last[-1] == UC('0')) { + --last; + ++zeroes; + } + return zeroes; +} + +// Discard a long suffix of zeroes before materializing the coefficient. The +// scientific exponent still comes from the original parsed number, so removing +// zeroes here is balanced by the scale derived from the shorter digit count. +template +fastfloat_really_inline FASTFLOAT_CONSTEXPR20 bool +trim_trailing_zeros(parsed_number_string_t &num) noexcept { + constexpr size_t minimum_trailing_zeroes = 16; + if (!has_trailing_zero(num)) { + return false; + } + + UC const *integer_end = num.integer.ptr + num.integer.len(); + UC const *fraction_end = num.fraction.ptr; + size_t trailing_zeroes = 0; + if (fraction_end != nullptr) { + fraction_end += num.fraction.len(); + trailing_zeroes = trim_zeros_from_end(num.fraction.ptr, fraction_end); + } + // Integer zeroes belong to the suffix only when every fractional digit was + // zero. For example, trimming 120.3000 must retain the zero in 120. + if (fraction_end == nullptr || fraction_end == num.fraction.ptr) { + trailing_zeroes += trim_zeros_from_end(num.integer.ptr, integer_end); + } + + // Do not turn an all-zero coefficient into empty spans, and retain short + // suffixes where a reverse scan does not recover its setup cost. + if (trailing_zeroes < minimum_trailing_zeroes || + (integer_end == num.integer.ptr && + (fraction_end == nullptr || fraction_end == num.fraction.ptr))) { + return false; + } + + num.integer = span( + num.integer.ptr, size_t(integer_end - num.integer.ptr)); + if (fraction_end != nullptr) { + num.fraction = span( + num.fraction.ptr, size_t(fraction_end - num.fraction.ptr)); + } + return true; +} + template inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa digit_comp(parsed_number_string_t &num, adjusted_mantissa am) noexcept { @@ -439,7 +515,15 @@ digit_comp(parsed_number_string_t &num, adjusted_mantissa am) noexcept { size_t max_digits = binary_format::max_digits(); size_t digits = 0; bigint bigmant; - parse_mantissa(bigmant, num, max_digits, digits); + parsed_number_string_t trimmed_num; + parsed_number_string_t *mantissa_num = # + if (has_trailing_zero(num)) { + trimmed_num = num; + if (trim_trailing_zeros(trimmed_num)) { + mantissa_num = &trimmed_num; + } + } + parse_mantissa(bigmant, *mantissa_num, max_digits, digits); // can't underflow, since digits is at most max_digits. int32_t exponent = sci_exp + 1 - int32_t(digits); if (exponent >= 0) { diff --git a/tests/trailing_zeros_test.cpp b/tests/trailing_zeros_test.cpp index 63a55efe..5f0e71e6 100644 --- a/tests/trailing_zeros_test.cpp +++ b/tests/trailing_zeros_test.cpp @@ -34,7 +34,14 @@ parse_result parse(std::string const &input) { double value = 0; fast_float::from_chars_result const result = fast_float::from_chars( input.data(), input.data() + input.size(), value); - return parse_result{bits(value), size_t(result.ptr - input.data()), result.ec}; + return parse_result{bits(value), size_t(result.ptr - input.data()), + result.ec}; +} + +fast_float::parsed_number_string parse_number(std::string const &input) { + fast_float::parse_options options; + return fast_float::parse_number_string( + input.data(), input.data() + input.size(), options, true); } bool takes_digit_comp(std::string const &input) { @@ -76,7 +83,8 @@ template parse_result parse_wide(std::string const &input) { double value = 0; fast_float::from_chars_result_t const result = fast_float::from_chars( wide.data(), wide.data() + wide.size(), value); - return parse_result{bits(value), size_t(result.ptr - wide.data()), result.ec}; + return parse_result{bits(value), size_t(result.ptr - wide.data()), + result.ec}; } template @@ -94,7 +102,8 @@ void check_equivalent_wide(std::string const &padded, } // namespace -TEST_CASE("long trailing zero coefficients preserve public from_chars results") { +TEST_CASE( + "long trailing zero coefficients preserve public from_chars results") { // The prefix is an ambiguous 19-digit mantissa at exponent -18. Adding a // twentieth digit makes public from_chars use the digit comparison fallback. std::string const prefix = "6497987825129815764"; @@ -162,3 +171,40 @@ TEST_CASE("all-zero coefficients retain their public result") { CHECK(fraction_result.value_bits == 0); } } + +TEST_CASE("logical trimming preserves integer and all-zero spans") { + std::string const zeroes16(16, '0'); + std::string const fraction_input = "120.3" + zeroes16; + fast_float::parsed_number_string fraction = parse_number(fraction_input); + REQUIRE(fast_float::trim_trailing_zeros(fraction)); + CHECK(fraction.integer.len() == 3); + CHECK(fraction.fraction.len() == 1); + CHECK(std::string(fraction.integer.ptr, fraction.integer.len()) == "120"); + CHECK(std::string(fraction.fraction.ptr, fraction.fraction.len()) == "3"); + + std::string const across_point_input = "120." + zeroes16; + fast_float::parsed_number_string across_point = + parse_number(across_point_input); + REQUIRE(fast_float::trim_trailing_zeros(across_point)); + CHECK(across_point.integer.len() == 2); + CHECK(across_point.fraction.len() == 0); + CHECK(std::string(across_point.integer.ptr, across_point.integer.len()) == + "12"); + + std::string const all_zero_input = "0." + std::string(64, '0'); + fast_float::parsed_number_string all_zero = parse_number(all_zero_input); + fast_float::span const all_zero_integer = all_zero.integer; + fast_float::span const all_zero_fraction = all_zero.fraction; + CHECK_FALSE(fast_float::trim_trailing_zeros(all_zero)); + CHECK(all_zero.integer.ptr == all_zero_integer.ptr); + CHECK(all_zero.integer.len() == all_zero_integer.len()); + CHECK(all_zero.fraction.ptr == all_zero_fraction.ptr); + CHECK(all_zero.fraction.len() == all_zero_fraction.len()); + + std::string const short_suffix_input = "120.3" + std::string(15, '0'); + fast_float::parsed_number_string short_suffix = + parse_number(short_suffix_input); + CHECK_FALSE(fast_float::trim_trailing_zeros(short_suffix)); + CHECK(short_suffix.integer.len() == 3); + CHECK(short_suffix.fraction.len() == 16); +}