fix for the parse_number_string

small improvements for the FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
This commit is contained in:
IRainman 2025-05-07 19:31:56 +03:00
parent 23a9c3f54d
commit f7d5037a4f

View File

@ -328,15 +328,24 @@ parse_number_string(UC const *p, UC const *pend,
#endif #endif
UC const *const start_digits = p; UC const *const start_digits = p;
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
while ((p != pend) && is_integer(*p)) { if (p != pend)
#endif
{
do {
if (is_integer(*p)) {
// a multiplication by 10 is cheaper than an arbitrary integer // a multiplication by 10 is cheaper than an arbitrary integer
// multiplication // multiplication
answer.mantissa = static_cast<fast_float::am_mant_t>( answer.mantissa = static_cast<fast_float::am_mant_t>(
answer.mantissa * 10 + answer.mantissa * 10 +
static_cast<fast_float::am_mant_t>( static_cast<fast_float::am_mant_t>(
*p - UC('0'))); // might overflow, we will handle the overflow later *p -
UC('0'))); // might overflow, we will handle the overflow later
++p; ++p;
} else {
break;
}
} while (p != pend);
} }
UC const *const end_of_integer_part = p; UC const *const end_of_integer_part = p;
@ -398,7 +407,8 @@ parse_number_string(UC const *p, UC const *pend,
bool neg_exp = false; bool neg_exp = false;
if (p != pend) { if (p != pend) {
UC const *location_of_e; UC const *location_of_e;
if (chars_format_t(options.format & chars_format::scientific)) { if (chars_format_t(options.format & chars_format::scientific) ||
chars_format_t(options.format & chars_format::fixed)) {
switch (*p) { switch (*p) {
case UC('e'): case UC('e'):
case UC('E'): case UC('E'):
@ -406,8 +416,8 @@ parse_number_string(UC const *p, UC const *pend,
++p; ++p;
break; break;
default: default:
// If it scientific and not fixed, we have to bail out.
if (!chars_format_t(options.format & chars_format::fixed)) { if (!chars_format_t(options.format & chars_format::fixed)) {
// It scientific and not fixed, we have to bail out.
return report_parse_error<UC>(p, return report_parse_error<UC>(p,
parse_error::missing_exponential_part); parse_error::missing_exponential_part);
} }
@ -424,13 +434,8 @@ parse_number_string(UC const *p, UC const *pend,
++p; ++p;
break; break;
default: default:
// If it scientific and not fixed, we have to bail out. // In scientific and fixed notations sign is optional.
if (!chars_format_t(options.format & chars_format::fixed)) { break;
return report_parse_error<UC>(
p, parse_error::missing_exponential_part);
}
// In fixed notation we will be ignoring the 'e'.
location_of_e = nullptr;
} }
} }
} }