# format.

This commit is contained in:
IRainman 2025-04-12 17:17:04 +03:00
parent ba1344c030
commit 0a18d6b329
4 changed files with 31 additions and 25 deletions

View File

@ -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<am_pow_t>(before - p);
answer.fraction = span<UC const>(before, static_cast<am_digits>(p - before));
answer.fraction =
span<UC const>(before, static_cast<am_digits>(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) ||

View File

@ -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 >=

View File

@ -69,14 +69,14 @@ to_extended(T const &value) noexcept {
adjusted_mantissa am;
am_pow_t bias = binary_format<T>::mantissa_explicit_bits() -
binary_format<T>::minimum_exponent();
binary_format<T>::minimum_exponent();
equiv_uint bits;
#if FASTFLOAT_HAS_BIT_CAST
bits =
bits =
#if FASTFLOAT_HAS_BIT_CAST == 1
std::
std::
#endif
bit_cast<equiv_uint>(value);
bit_cast<equiv_uint>(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<T>::mantissa_explicit_bits());
binary_format<T>::mantissa_explicit_bits());
am.power2 -= bias;
am.mantissa = (bits & mantissa_mask) | hidden_bit_mask;
}
@ -147,7 +147,8 @@ template <typename callback>
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<T>::mantissa_explicit_bits() -
binary_format<T>::minimum_exponent();
binary_format<T>::minimum_exponent();
am.power2 = bigmant.bit_length() - 64 + bias;
round<T>(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<T>(am_b,
[](adjusted_mantissa &a, am_pow_t shift) { round_down(a, shift); });
round<T>(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,

View File

@ -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<float>::min_exponent_round_to_even() {
return -17;
}
template <> inline constexpr am_pow_t binary_format<double>::minimum_exponent() {
template <>
inline constexpr am_pow_t binary_format<double>::minimum_exponent() {
return -1023;
}
@ -669,7 +669,8 @@ inline constexpr am_pow_t binary_format<float>::max_exponent_fast_path() {
}
template <typename T>
inline constexpr binary_format<T>::equiv_uint binary_format<T>::max_mantissa_fast_path() {
inline constexpr binary_format<T>::equiv_uint
binary_format<T>::max_mantissa_fast_path() {
return binary_format<T>::equiv_uint(2) << mantissa_explicit_bits();
}
@ -786,7 +787,8 @@ inline constexpr am_bits_t binary_format<std::float16_t>::sign_index() {
#endif
template <>
inline constexpr am_exp_t binary_format<std::float16_t>::largest_power_of_ten() {
inline constexpr am_exp_t
binary_format<std::float16_t>::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<unsigned char>(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];
}