mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-07 01:06:48 +08:00
# format.
This commit is contained in:
parent
ba1344c030
commit
0a18d6b329
@ -334,8 +334,7 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
// multiplication
|
// multiplication
|
||||||
answer.mantissa =
|
answer.mantissa =
|
||||||
10 * answer.mantissa +
|
10 * answer.mantissa +
|
||||||
UC(*p -
|
UC(*p - UC('0')); // might overflow, we will handle the overflow later
|
||||||
UC('0')); // might overflow, we will handle the overflow later
|
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
UC const *const end_of_integer_part = p;
|
UC const *const end_of_integer_part = p;
|
||||||
@ -371,7 +370,8 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
answer.exponent = static_cast<am_pow_t>(before - 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;
|
digit_count -= answer.exponent;
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
|
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
|
||||||
@ -390,7 +390,8 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
|
|
||||||
// Now we can parse the explicit exponential part.
|
// Now we can parse the explicit exponential part.
|
||||||
am_pow_t exp_number = 0; // explicit exponential part
|
am_pow_t exp_number = 0; // explicit exponential part
|
||||||
if ((p != pend) && (chars_format_t(options.format & chars_format::scientific) &&
|
if ((p != pend) &&
|
||||||
|
(chars_format_t(options.format & chars_format::scientific) &&
|
||||||
(UC('e') == *p) ||
|
(UC('e') == *p) ||
|
||||||
(UC('E') == *p))
|
(UC('E') == *p))
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
|
|||||||
@ -147,7 +147,8 @@ template <typename callback>
|
|||||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 void
|
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 void
|
||||||
round_nearest_tie_even(adjusted_mantissa &am, am_pow_t shift,
|
round_nearest_tie_even(adjusted_mantissa &am, am_pow_t shift,
|
||||||
callback cb) noexcept {
|
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 const halfway = (shift == 0) ? 0 : am_mant_t(1) << (shift - 1);
|
||||||
am_mant_t truncated_bits = am.mantissa & mask;
|
am_mant_t truncated_bits = am.mantissa & mask;
|
||||||
bool is_above = truncated_bits > halfway;
|
bool is_above = truncated_bits > halfway;
|
||||||
@ -385,8 +386,9 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp(
|
|||||||
adjusted_mantissa am_b = am;
|
adjusted_mantissa am_b = am;
|
||||||
// gcc7 bug: use a lambda to remove the noexcept qualifier bug with
|
// gcc7 bug: use a lambda to remove the noexcept qualifier bug with
|
||||||
// -Wnoexcept-type.
|
// -Wnoexcept-type.
|
||||||
round<T>(am_b,
|
round<T>(am_b, [](adjusted_mantissa &a, am_pow_t shift) {
|
||||||
[](adjusted_mantissa &a, am_pow_t shift) { round_down(a, shift); });
|
round_down(a, shift);
|
||||||
|
});
|
||||||
to_float(
|
to_float(
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
false,
|
false,
|
||||||
|
|||||||
@ -408,9 +408,8 @@ umul128_generic(uint64_t ab, uint64_t cd, uint64_t *hi) noexcept {
|
|||||||
|
|
||||||
// slow emulation routine for 32-bit
|
// slow emulation routine for 32-bit
|
||||||
#if !defined(__MINGW64__)
|
#if !defined(__MINGW64__)
|
||||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 uint64_t _umul128(uint64_t ab,
|
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 uint64_t
|
||||||
uint64_t cd,
|
_umul128(uint64_t ab, uint64_t cd, uint64_t *hi) noexcept {
|
||||||
uint64_t *hi) noexcept {
|
|
||||||
return umul128_generic(ab, cd, hi);
|
return umul128_generic(ab, cd, hi);
|
||||||
}
|
}
|
||||||
#endif // !__MINGW64__
|
#endif // !__MINGW64__
|
||||||
@ -630,7 +629,8 @@ inline constexpr am_pow_t binary_format<float>::min_exponent_round_to_even() {
|
|||||||
return -17;
|
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;
|
return -1023;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,7 +669,8 @@ inline constexpr am_pow_t binary_format<float>::max_exponent_fast_path() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
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();
|
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
|
#endif
|
||||||
|
|
||||||
template <>
|
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;
|
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)];
|
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];
|
return int_luts<>::maxdigits_u64[base - 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user