@@ -223,8 +223,8 @@ is_truncated(span<UC const> s) noexcept {
223223
224224template <typename UC>
225225fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
226- parse_eight_digits (UC const *&p, limb &value, uint32_t &counter,
227- uint32_t &count) noexcept {
226+ parse_eight_digits (UC const *&p, limb &value, uint16_t &counter,
227+ uint16_t &count) noexcept {
228228 value = value * 100000000 + parse_eight_digits_unrolled (p);
229229 p += 8 ;
230230 counter += 8 ;
@@ -233,12 +233,12 @@ parse_eight_digits(UC const *&p, limb &value, uint32_t &counter,
233233
234234template <typename UC>
235235fastfloat_really_inline FASTFLOAT_CONSTEXPR14 void
236- parse_one_digit (UC const *&p, limb &value, uint32_t &counter,
237- uint32_t &count) noexcept {
236+ parse_one_digit (UC const *&p, limb &value, uint16_t &counter,
237+ uint16_t &count) noexcept {
238238 value = value * 10 + limb (*p - UC (' 0' ));
239- p++ ;
240- counter++ ;
241- count++ ;
239+ ++p ;
240+ ++counter ;
241+ ++count ;
242242}
243243
244244fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
@@ -248,28 +248,28 @@ add_native(bigint &big, limb power, limb value) noexcept {
248248}
249249
250250fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
251- round_up_bigint (bigint &big, uint32_t &count) noexcept {
251+ round_up_bigint (bigint &big, uint16_t &count) noexcept {
252252 // need to round-up the digits, but need to avoid rounding
253253 // ....9999 to ...10000, which could cause a false halfway point.
254254 add_native (big, 10 , 1 );
255- count++ ;
255+ ++count ;
256256}
257257
258258// parse the significant digits into a big integer
259- template <typename UC>
260- inline FASTFLOAT_CONSTEXPR20 void
261- parse_mantissa (bigint &result, const parsed_number_string_t <UC> &num,
262- uint32_t const max_digits, uint32_t &digits) noexcept {
259+ template <typename T, typename UC>
260+ inline FASTFLOAT_CONSTEXPR20 uint16_t
261+ parse_mantissa (bigint &result, const parsed_number_string_t <UC> &num) noexcept {
263262 // try to minimize the number of big integer and scalar multiplication.
264263 // therefore, try to parse 8 digits at a time, and multiply by the largest
265264 // scalar value (9 or 19 digits) for each step.
266- uint32_t counter = 0 ;
267- digits = 0 ;
265+ uint16_t const max_digits = uint16_t (binary_format<T>::max_digits ());
266+ uint16_t counter = 0 ;
267+ uint16_t digits = 0 ;
268268 limb value = 0 ;
269269#ifdef FASTFLOAT_64BIT_LIMB
270- uint32_t const step = 19 ;
270+ uint16_t const step = 19 ;
271271#else
272- uint32_t const step = 9 ;
272+ uint16_t const step = 9 ;
273273#endif
274274
275275 // process all integer digits.
@@ -280,10 +280,10 @@ parse_mantissa(bigint &result, const parsed_number_string_t<UC> &num,
280280 while (p != pend) {
281281 while ((std::distance (p, pend) >= 8 ) && (step - counter >= 8 ) &&
282282 (max_digits - digits >= 8 )) {
283- parse_eight_digits (p, value, counter, digits);
283+ parse_eight_digits<UC> (p, value, counter, digits);
284284 }
285285 while (counter < step && p != pend && digits < max_digits) {
286- parse_one_digit (p, value, counter, digits);
286+ parse_one_digit<UC> (p, value, counter, digits);
287287 }
288288 if (digits == max_digits) {
289289 // add the temporary value, then check if we've truncated any digits
@@ -295,7 +295,7 @@ parse_mantissa(bigint &result, const parsed_number_string_t<UC> &num,
295295 if (truncated) {
296296 round_up_bigint (result, digits);
297297 }
298- return ;
298+ return digits ;
299299 } else {
300300 add_native (result, limb (powers_of_ten_uint64[counter]), value);
301301 counter = 0 ;
@@ -314,10 +314,10 @@ parse_mantissa(bigint &result, const parsed_number_string_t<UC> &num,
314314 while (p != pend) {
315315 while ((std::distance (p, pend) >= 8 ) && (step - counter >= 8 ) &&
316316 (max_digits - digits >= 8 )) {
317- parse_eight_digits (p, value, counter, digits);
317+ parse_eight_digits<UC> (p, value, counter, digits);
318318 }
319319 while (counter < step && p != pend && digits < max_digits) {
320- parse_one_digit (p, value, counter, digits);
320+ parse_one_digit<UC> (p, value, counter, digits);
321321 }
322322 if (digits == max_digits) {
323323 // add the temporary value, then check if we've truncated any digits
@@ -326,7 +326,7 @@ parse_mantissa(bigint &result, const parsed_number_string_t<UC> &num,
326326 if (truncated) {
327327 round_up_bigint (result, digits);
328328 }
329- return ;
329+ return digits ;
330330 } else {
331331 add_native (result, limb (powers_of_ten_uint64[counter]), value);
332332 counter = 0 ;
@@ -338,6 +338,7 @@ parse_mantissa(bigint &result, const parsed_number_string_t<UC> &num,
338338 if (counter != 0 ) {
339339 add_native (result, limb (powers_of_ten_uint64[counter]), value);
340340 }
341+ return digits;
341342}
342343
343344template <typename T>
@@ -440,13 +441,12 @@ inline FASTFLOAT_CONSTEXPR20 void digit_comp(
440441 // remove the invalid exponent bias
441442 am.power2 -= invalid_am_bias;
442443
443- int32_t sci_exp = scientific_exponent (num);
444- uint32_t const max_digits = uint32_t (binary_format<T>::max_digits ());
445- uint32_t digits = 0 ;
446444 bigint bigmant;
447- parse_mantissa (bigmant, num, max_digits, digits);
445+ int32_t const sci_exp = scientific_exponent (num);
446+
447+ uint16_t const digits = parse_mantissa<T, UC>(bigmant, num);
448448 // can't underflow, since digits is at most max_digits.
449- int32_t exponent = sci_exp + 1 - digits;
449+ int32_t const exponent = sci_exp + 1 - digits;
450450 if (exponent >= 0 ) {
451451 positive_digit_comp<T>(bigmant, am, exponent);
452452 } else {
0 commit comments