This commit is contained in:
IRainman 2025-03-12 20:23:05 +03:00
parent f3c60527d5
commit 27c0cd581c
3 changed files with 47 additions and 41 deletions

View File

@ -208,7 +208,8 @@ template <typename UC>
template <typename UC, FASTFLOAT_ENABLE_IF(!has_simd_opt<UC>()) = 0> template <typename UC, FASTFLOAT_ENABLE_IF(!has_simd_opt<UC>()) = 0>
#endif #endif
// dummy for compile // dummy for compile
FASTFLOAT_CONSTEVAL20 bool simd_parse_if_eight_digits_unrolled(UC const *, uint64_t &) { FASTFLOAT_CONSTEVAL20 bool simd_parse_if_eight_digits_unrolled(UC const *,
uint64_t &) {
return 0; return 0;
} }
@ -317,8 +318,8 @@ parse_number_string(UC const *p, UC const *pend,
} }
else { else {
if (!is_integer(*p) && if (!is_integer(*p) &&
(*p != (*p != options.decimal_point)) { // a sign must be followed by an
options.decimal_point)) { // a sign must be followed by an integer or the dot // integer or the dot
return report_parse_error<UC>( return report_parse_error<UC>(
p, parse_error::missing_integer_or_dot_after_sign); p, parse_error::missing_integer_or_dot_after_sign);
} }
@ -385,8 +386,8 @@ parse_number_string(UC const *p, UC const *pend,
((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
|| (uint64_t(options.format & detail::basic_fortran_fmt) && || (uint64_t(options.format & detail::basic_fortran_fmt) &&
((UC('+') == *p) || (UC('-') == *p) || ((UC('+') == *p) || (UC('-') == *p) || (UC('d') == *p) ||
(UC('d') == *p) || (UC('D') == *p))) (UC('D') == *p)))
#endif #endif
) { ) {
UC const *location_of_e = p; UC const *location_of_e = p;
@ -399,10 +400,11 @@ parse_number_string(UC const *p, UC const *pend,
} }
bool neg_exp = false; bool neg_exp = false;
if (p != pend) { if (p != pend) {
if ( UC('-') == *p) { if (UC('-') == *p) {
neg_exp = true; neg_exp = true;
++p; ++p;
} else if (UC('+') == *p) { // '+' on exponent is allowed by C++17 20.19.3.(7.1) } else if (UC('+') ==
*p) { // '+' on exponent is allowed by C++17 20.19.3.(7.1)
++p; ++p;
} }
} }
@ -449,8 +451,8 @@ parse_number_string(UC const *p, UC const *pend,
// We need to be mindful of the case where we only have zeroes... // We need to be mindful of the case where we only have zeroes...
// E.g., 0.000000000...000. // E.g., 0.000000000...000.
UC const *start = start_digits; UC const *start = start_digits;
while ((start != pend) && (*start == UC('0') || while ((start != pend) &&
*start == options.decimal_point)) { (*start == UC('0') || *start == options.decimal_point)) {
if (*start == UC('0')) { if (*start == UC('0')) {
digit_count--; digit_count--;
} }
@ -513,7 +515,8 @@ parse_int_string(UC const *p, UC const *pend, T &value,
return answer; return answer;
} }
if ((*p == UC('-')) || if ((*p == UC('-')) ||
(uint64_t(options.format & chars_format::allow_leading_plus) && (*p == UC('+')))) { (uint64_t(options.format & chars_format::allow_leading_plus) &&
(*p == UC('+')))) {
++p; ++p;
} }
#endif #endif
@ -538,7 +541,8 @@ parse_int_string(UC const *p, UC const *pend, T &value,
if (digit >= options.base) { if (digit >= options.base) {
break; break;
} }
i = static_cast<uint64_t>(options.base) * i + digit; // might overflow, check this later i = static_cast<uint64_t>(options.base) * i +
digit; // might overflow, check this later
p++; p++;
} }

View File

@ -369,8 +369,9 @@ positive_digit_comp(bigint &bigmant, int32_t exponent) noexcept {
// we then need to scale by `2^(f- e)`, and then the two significant digits // we then need to scale by `2^(f- e)`, and then the two significant digits
// are of the same magnitude. // are of the same magnitude.
template <typename T> template <typename T>
inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp( inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
bigint &bigmant, const adjusted_mantissa& am, const int32_t exponent) noexcept { negative_digit_comp(bigint &bigmant, const adjusted_mantissa &am,
const int32_t exponent) noexcept {
bigint &real_digits = bigmant; bigint &real_digits = bigmant;
const int32_t &real_exp = exponent; const int32_t &real_exp = exponent;
@ -437,8 +438,8 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp(
// the actual digits. we then compare the big integer representations // the actual digits. we then compare the big integer representations
// of both, and use that to direct rounding. // of both, and use that to direct rounding.
template <typename T, typename UC> template <typename T, typename UC>
inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa digit_comp(
digit_comp(const parsed_number_string_t<UC> &num, adjusted_mantissa& am) noexcept { const parsed_number_string_t<UC> &num, adjusted_mantissa &am) noexcept {
// remove the invalid exponent bias // remove the invalid exponent bias
am.power2 -= invalid_am_bias; am.power2 -= invalid_am_bias;

View File

@ -51,7 +51,8 @@ from_chars_advanced(UC const *first, UC const *last, T &value,
template <typename T, typename UC = char, template <typename T, typename UC = char,
typename = FASTFLOAT_ENABLE_IF(is_supported_integer_type<T>::value)> typename = FASTFLOAT_ENABLE_IF(is_supported_integer_type<T>::value)>
FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC> FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
from_chars(UC const *first, UC const *last, T &value, int const base = 10) noexcept; from_chars(UC const *first, UC const *last, T &value,
int const base = 10) noexcept;
} // namespace fast_float } // namespace fast_float