From fe0bce5eb7e810a8d21182a47ef3ff7d3d5329de Mon Sep 17 00:00:00 2001 From: IRainman Date: Tue, 21 Oct 2025 21:08:08 +0300 Subject: [PATCH] # const and constexpr fixes # types fixes. # FASTFLOAT_ASSERT fix. --- include/fast_float/digit_comparison.h | 4 ++-- include/fast_float/fast_table.h | 10 +++++----- include/fast_float/float_common.h | 7 +++---- include/fast_float/parse_number.h | 5 +++-- tests/basictest.cpp | 27 ++++++++++++++++----------- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/include/fast_float/digit_comparison.h b/include/fast_float/digit_comparison.h index 0380df7..78ec5de 100644 --- a/include/fast_float/digit_comparison.h +++ b/include/fast_float/digit_comparison.h @@ -270,9 +270,9 @@ parse_mantissa(bigint &result, const parsed_number_string_t &num) noexcept { am_digits digits = 0; limb value = 0; #ifdef FASTFLOAT_64BIT_LIMB - am_digits const step = 19; + constexpr am_digits step = 19; #else - am_digits const step = 9; + constexpr am_digits step = 9; #endif // process all integer digits. diff --git a/include/fast_float/fast_table.h b/include/fast_float/fast_table.h index 69f9b2c..536e149 100644 --- a/include/fast_float/fast_table.h +++ b/include/fast_float/fast_table.h @@ -31,14 +31,14 @@ namespace fast_float { */ template struct powers_template { - constexpr static int smallest_power_of_five = + constexpr static am_pow_t smallest_power_of_five = binary_format::smallest_power_of_ten(); - constexpr static int largest_power_of_five = + constexpr static am_pow_t largest_power_of_five = binary_format::largest_power_of_ten(); - constexpr static int number_of_entries = + constexpr static am_digits number_of_entries = 2 * (largest_power_of_five - smallest_power_of_five + 1); // Powers of five from 5^-342 all the way to 5^308 rounded toward one. - constexpr static uint64_t power_of_five_128[number_of_entries] = { + constexpr static am_mant_t power_of_five_128[number_of_entries] = { 0xeef453d6923bd65a, 0x113faa2906a13b3f, 0x9558b4661b6565f8, 0x4ac7ca59a424c507, 0xbaaee17fa23ebf76, 0x5d79bcf00d2df649, @@ -696,7 +696,7 @@ template struct powers_template { #if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE template -constexpr uint64_t +constexpr am_mant_t powers_template::power_of_five_128[number_of_entries]; #endif diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 66a96d9..e34c4e0 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -83,7 +83,9 @@ template struct parse_options_t { constexpr explicit parse_options_t( chars_format const fmt = chars_format::general, UC const dot = UC('.'), uint_fast8_t const b = 10) noexcept - : format(fmt), decimal_point(dot), base(b) {} + : format(fmt), decimal_point(dot), base(b) { + FASTFLOAT_ASSUME(base >= 2 && base <= 36); + } /** Which number formats are accepted */ chars_format format; @@ -91,7 +93,6 @@ template struct parse_options_t { UC decimal_point; /** The base used for integers */ uint_fast8_t base; /* only allowed from 2 to 36 */ - FASTFLOAT_ASSUME(base >= 2 && base <= 36); }; using parse_options = parse_options_t; @@ -214,7 +215,6 @@ using parse_options = parse_options_t; #define FASTFLOAT_ASSERT(x) \ { \ ((void)(x)); \ - FASTFLOAT_ASSUME(x); \ } #endif @@ -222,7 +222,6 @@ using parse_options = parse_options_t; #define FASTFLOAT_DEBUG_ASSERT(x) \ { \ ((void)(x)); \ - FASTFLOAT_ASSUME(x); \ } #endif diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index fed5605..fd76eda 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -437,12 +437,13 @@ FASTFLOAT_CONSTEXPR20 } FASTFLOAT_CONSTEXPR20 inline double -integer_times_pow10(uint64_t mantissa, int const decimal_exponent) noexcept { +integer_times_pow10(uint64_t const mantissa, + int const decimal_exponent) noexcept { return integer_times_pow10(mantissa, decimal_exponent); } FASTFLOAT_CONSTEXPR20 inline double -integer_times_pow10(int64_t mantissa, int const decimal_exponent) noexcept { +integer_times_pow10(int64_t const mantissa, int const decimal_exponent) noexcept { return integer_times_pow10(mantissa, decimal_exponent); } diff --git a/tests/basictest.cpp b/tests/basictest.cpp index 3337075..671ec3d 100644 --- a/tests/basictest.cpp +++ b/tests/basictest.cpp @@ -2126,8 +2126,9 @@ TEST_CASE("bfloat16.general") { #endif template -void verify_integer_times_pow10_result(Int mantissa, int decimal_exponent, - T actual, U expected) { +void verify_integer_times_pow10_result(Int const mantissa, + int const decimal_exponent, + T const actual, U const expected) { static_assert(std::is_same::value, "expected and actual types must match"); @@ -2144,8 +2145,8 @@ void verify_integer_times_pow10_result(Int mantissa, int decimal_exponent, } template -T calculate_integer_times_pow10_expected_result(Int mantissa, - int decimal_exponent) { +T calculate_integer_times_pow10_expected_result(Int const mantissa, + int const decimal_exponent) { std::string constructed_string = std::to_string(mantissa) + "e" + std::to_string(decimal_exponent); T expected_result; @@ -2158,8 +2159,9 @@ T calculate_integer_times_pow10_expected_result(Int mantissa, } template -void verify_integer_times_pow10_dflt(Int mantissa, int decimal_exponent, - double expected) { +void verify_integer_times_pow10_dflt(Int const mantissa, + int const decimal_exponent, + double const expected) { static_assert(std::is_integral::value); // the "default" overload @@ -2171,7 +2173,8 @@ void verify_integer_times_pow10_dflt(Int mantissa, int decimal_exponent, } template -void verify_integer_times_pow10_dflt(Int mantissa, int decimal_exponent) { +void verify_integer_times_pow10_dflt(Int const mantissa, + int const decimal_exponent) { static_assert(std::is_integral::value); const auto expected_result = @@ -2182,8 +2185,8 @@ void verify_integer_times_pow10_dflt(Int mantissa, int decimal_exponent) { } template -void verify_integer_times_pow10(Int mantissa, int decimal_exponent, - T expected) { +void verify_integer_times_pow10(Int const mantissa, int const decimal_exponent, + T const expected) { static_assert(std::is_floating_point::value); static_assert(std::is_integral::value); @@ -2196,7 +2199,8 @@ void verify_integer_times_pow10(Int mantissa, int decimal_exponent, } template -void verify_integer_times_pow10(Int mantissa, int decimal_exponent) { +void verify_integer_times_pow10(Int const mantissa, + int const decimal_exponent) { static_assert(std::is_floating_point::value); static_assert(std::is_integral::value); @@ -2208,7 +2212,8 @@ void verify_integer_times_pow10(Int mantissa, int decimal_exponent) { namespace all_supported_types { template -void verify_integer_times_pow10(Int mantissa, int decimal_exponent) { +void verify_integer_times_pow10(Int const mantissa, + int const decimal_exponent) { static_assert(std::is_integral::value); // verify the "default" overload