From 0a18d6b329a7dd80914c2f789a6c5f4a2d4f9f7e Mon Sep 17 00:00:00 2001 From: IRainman Date: Sat, 12 Apr 2025 17:17:04 +0300 Subject: [PATCH] # format. --- include/fast_float/ascii_number.h | 13 +++++++------ include/fast_float/decimal_to_binary.h | 4 ++-- include/fast_float/digit_comparison.h | 20 +++++++++++--------- include/fast_float/float_common.h | 19 +++++++++++-------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index a2c84dd..dab21f2 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -334,8 +334,7 @@ parse_number_string(UC const *p, UC const *pend, // multiplication answer.mantissa = 10 * answer.mantissa + - UC(*p - - UC('0')); // might overflow, we will handle the overflow later + UC(*p - UC('0')); // might overflow, we will handle the overflow later ++p; } UC const *const end_of_integer_part = p; @@ -371,7 +370,8 @@ parse_number_string(UC const *p, UC const *pend, ++p; } answer.exponent = static_cast(before - p); - answer.fraction = span(before, static_cast(p - before)); + answer.fraction = + span(before, static_cast(p - before)); digit_count -= answer.exponent; #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) { @@ -390,9 +390,10 @@ parse_number_string(UC const *p, UC const *pend, // Now we can parse the explicit exponential part. am_pow_t exp_number = 0; // explicit exponential part - if ((p != pend) && (chars_format_t(options.format & chars_format::scientific) && - (UC('e') == *p) || - (UC('E') == *p)) + if ((p != pend) && + (chars_format_t(options.format & chars_format::scientific) && + (UC('e') == *p) || + (UC('E') == *p)) #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN || (chars_format_t(options.format & detail::basic_fortran_fmt) && ((UC('+') == *p) || (UC('-') == *p) || (UC('d') == *p) || diff --git a/include/fast_float/decimal_to_binary.h b/include/fast_float/decimal_to_binary.h index 6a794fe..e0db653 100644 --- a/include/fast_float/decimal_to_binary.h +++ b/include/fast_float/decimal_to_binary.h @@ -77,7 +77,7 @@ compute_error_scaled(int64_t q, uint64_t w, int32_t lz) noexcept { answer.mantissa = w << hilz; int32_t bias = binary::mantissa_explicit_bits() - binary::minimum_exponent(); answer.power2 = am_pow_t(detail::power(int32_t(q)) + bias - hilz - lz - 62 + - invalid_am_bias); + invalid_am_bias); return answer; } @@ -144,7 +144,7 @@ compute_float(int64_t q, uint64_t w) noexcept { answer.mantissa = product.high >> shift; answer.power2 = am_pow_t(detail::power(int32_t(q)) + upperbit - lz - - binary::minimum_exponent()); + binary::minimum_exponent()); if (answer.power2 <= 0) { // we have a subnormal or very small value. // Here have that answer.power2 <= 0 so -answer.power2 >= 0 if (-answer.power2 + 1 >= diff --git a/include/fast_float/digit_comparison.h b/include/fast_float/digit_comparison.h index 73c2d42..ba3a5bc 100644 --- a/include/fast_float/digit_comparison.h +++ b/include/fast_float/digit_comparison.h @@ -69,14 +69,14 @@ to_extended(T const &value) noexcept { adjusted_mantissa am; am_pow_t bias = binary_format::mantissa_explicit_bits() - - binary_format::minimum_exponent(); + binary_format::minimum_exponent(); equiv_uint bits; #if FASTFLOAT_HAS_BIT_CAST - bits = + bits = #if FASTFLOAT_HAS_BIT_CAST == 1 - std:: + std:: #endif - bit_cast(value); + bit_cast(value); #else ::memcpy(&bits, &value, sizeof(T)); #endif @@ -87,7 +87,7 @@ to_extended(T const &value) noexcept { } else { // normal am.power2 = am_pow_t((bits & exponent_mask) >> - binary_format::mantissa_explicit_bits()); + binary_format::mantissa_explicit_bits()); am.power2 -= bias; am.mantissa = (bits & mantissa_mask) | hidden_bit_mask; } @@ -147,7 +147,8 @@ template fastfloat_really_inline FASTFLOAT_CONSTEXPR14 void round_nearest_tie_even(adjusted_mantissa &am, am_pow_t shift, callback cb) noexcept { - am_mant_t const mask = (shift == 64) ? UINT64_MAX : (am_mant_t(1) << shift) - 1; + am_mant_t const mask = + (shift == 64) ? UINT64_MAX : (am_mant_t(1) << shift) - 1; am_mant_t const halfway = (shift == 0) ? 0 : am_mant_t(1) << (shift - 1); am_mant_t truncated_bits = am.mantissa & mask; bool is_above = truncated_bits > halfway; @@ -352,7 +353,7 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa positive_digit_comp( bool truncated; am.mantissa = bigmant.hi64(truncated); am_pow_t bias = binary_format::mantissa_explicit_bits() - - binary_format::minimum_exponent(); + binary_format::minimum_exponent(); am.power2 = bigmant.bit_length() - 64 + bias; round(am, [truncated](adjusted_mantissa &a, am_pow_t shift) { @@ -385,8 +386,9 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp( adjusted_mantissa am_b = am; // gcc7 bug: use a lambda to remove the noexcept qualifier bug with // -Wnoexcept-type. - round(am_b, - [](adjusted_mantissa &a, am_pow_t shift) { round_down(a, shift); }); + round(am_b, [](adjusted_mantissa &a, am_pow_t shift) { + round_down(a, shift); + }); to_float( #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN false, diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index b850a4f..e452129 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -408,9 +408,8 @@ umul128_generic(uint64_t ab, uint64_t cd, uint64_t *hi) noexcept { // slow emulation routine for 32-bit #if !defined(__MINGW64__) -fastfloat_really_inline FASTFLOAT_CONSTEXPR14 uint64_t _umul128(uint64_t ab, - uint64_t cd, - uint64_t *hi) noexcept { +fastfloat_really_inline FASTFLOAT_CONSTEXPR14 uint64_t +_umul128(uint64_t ab, uint64_t cd, uint64_t *hi) noexcept { return umul128_generic(ab, cd, hi); } #endif // !__MINGW64__ @@ -449,7 +448,7 @@ typedef uint64_t am_mant_t; // Size of bits in the mantissa. typedef uint8_t am_bits_t; -// Power bias is signed for handling a denormal float +// Power bias is signed for handling a denormal float // or an invalid mantissa. typedef int16_t am_pow_t; @@ -630,7 +629,8 @@ inline constexpr am_pow_t binary_format::min_exponent_round_to_even() { return -17; } -template <> inline constexpr am_pow_t binary_format::minimum_exponent() { +template <> +inline constexpr am_pow_t binary_format::minimum_exponent() { return -1023; } @@ -669,7 +669,8 @@ inline constexpr am_pow_t binary_format::max_exponent_fast_path() { } template -inline constexpr binary_format::equiv_uint binary_format::max_mantissa_fast_path() { +inline constexpr binary_format::equiv_uint +binary_format::max_mantissa_fast_path() { return binary_format::equiv_uint(2) << mantissa_explicit_bits(); } @@ -786,7 +787,8 @@ inline constexpr am_bits_t binary_format::sign_index() { #endif template <> -inline constexpr am_exp_t binary_format::largest_power_of_ten() { +inline constexpr am_exp_t +binary_format::largest_power_of_ten() { return 4; } @@ -1197,7 +1199,8 @@ fastfloat_really_inline constexpr uint8_t ch_to_digit(UC c) noexcept { return int_luts<>::chdigit[static_cast(c)]; } -fastfloat_really_inline constexpr uint8_t max_digits_u64(uint8_t base) noexcept { +fastfloat_really_inline constexpr uint8_t +max_digits_u64(uint8_t base) noexcept { return int_luts<>::maxdigits_u64[base - 2]; }