mirror of
https://github.com/fastfloat/fast_float.git
synced 2026-02-09 11:16:45 +08:00
Handle digit separators in exponent and fraction parsing
This commit is contained in:
parent
587d890fa0
commit
b50eeab22a
@ -401,7 +401,10 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
// can occur at most twice without overflowing, but let it occur more, since
|
// can occur at most twice without overflowing, but let it occur more, since
|
||||||
// for integers with many digits, digit parsing is the primary bottleneck.
|
// for integers with many digits, digit parsing is the primary bottleneck.
|
||||||
if (options.digit_separator == UC('\0')) {
|
if (options.digit_separator == UC('\0')) {
|
||||||
|
UC const *const before_simd = p;
|
||||||
loop_parse_if_eight_digits(p, pend, i);
|
loop_parse_if_eight_digits(p, pend, i);
|
||||||
|
size_t const exploded = size_t(p - before_simd);
|
||||||
|
fractional_digit_count += int64_t(exploded);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (p != pend) {
|
while (p != pend) {
|
||||||
@ -523,10 +526,21 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
if (i >= minimal_nineteen_digit_integer) { // We have a big integer
|
if (i >= minimal_nineteen_digit_integer) { // We have a big integer
|
||||||
exponent = end_of_integer_part - p + exp_number;
|
int64_t remaining_integer_digits = 0;
|
||||||
|
while (p != int_end) {
|
||||||
|
if (options.digit_separator != UC('\0') &&
|
||||||
|
*p == options.digit_separator) {
|
||||||
|
++p;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++p;
|
||||||
|
++remaining_integer_digits;
|
||||||
|
}
|
||||||
|
exponent = remaining_integer_digits + exp_number;
|
||||||
} else { // We have a value with a fractional component.
|
} else { // We have a value with a fractional component.
|
||||||
p = answer.fraction.ptr;
|
p = answer.fraction.ptr;
|
||||||
UC const *frac_end = p + answer.fraction.len();
|
UC const *frac_end = p + answer.fraction.len();
|
||||||
|
int64_t fraction_digits_consumed = 0;
|
||||||
while ((i < minimal_nineteen_digit_integer) && (p != frac_end)) {
|
while ((i < minimal_nineteen_digit_integer) && (p != frac_end)) {
|
||||||
if (options.digit_separator != UC('\0') &&
|
if (options.digit_separator != UC('\0') &&
|
||||||
*p == options.digit_separator) {
|
*p == options.digit_separator) {
|
||||||
@ -535,8 +549,9 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
}
|
}
|
||||||
i = i * 10 + uint64_t(*p - UC('0'));
|
i = i * 10 + uint64_t(*p - UC('0'));
|
||||||
++p;
|
++p;
|
||||||
|
++fraction_digits_consumed;
|
||||||
}
|
}
|
||||||
exponent = answer.fraction.ptr - p + exp_number;
|
exponent = exp_number - fraction_digits_consumed;
|
||||||
}
|
}
|
||||||
// We have now corrected both exponent and i, to a truncated value
|
// We have now corrected both exponent and i, to a truncated value
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user