mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
fix for the parse_number_string
small improvements for the FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
This commit is contained in:
parent
23a9c3f54d
commit
f7d5037a4f
@ -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)
|
||||||
// a multiplication by 10 is cheaper than an arbitrary integer
|
#endif
|
||||||
// multiplication
|
{
|
||||||
answer.mantissa = static_cast<fast_float::am_mant_t>(
|
do {
|
||||||
answer.mantissa * 10 +
|
if (is_integer(*p)) {
|
||||||
static_cast<fast_float::am_mant_t>(
|
// a multiplication by 10 is cheaper than an arbitrary integer
|
||||||
*p - UC('0'))); // might overflow, we will handle the overflow later
|
// multiplication
|
||||||
++p;
|
answer.mantissa = static_cast<fast_float::am_mant_t>(
|
||||||
|
answer.mantissa * 10 +
|
||||||
|
static_cast<fast_float::am_mant_t>(
|
||||||
|
*p -
|
||||||
|
UC('0'))); // might overflow, we will handle the overflow later
|
||||||
|
++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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user