parse the significant digits into a big integer
| 2682 | |
| 2683 | // parse the significant digits into a big integer |
| 2684 | inline void parse_mantissa(bigint& result, parsed_number_string& num, size_t max_digits, size_t& digits) noexcept { |
| 2685 | // try to minimize the number of big integer and scalar multiplication. |
| 2686 | // therefore, try to parse 8 digits at a time, and multiply by the largest |
| 2687 | // scalar value (9 or 19 digits) for each step. |
| 2688 | size_t counter = 0; |
| 2689 | digits = 0; |
| 2690 | limb value = 0; |
| 2691 | #ifdef FASTFLOAT_64BIT_LIMB |
| 2692 | size_t step = 19; |
| 2693 | #else |
| 2694 | size_t step = 9; |
| 2695 | #endif |
| 2696 | |
| 2697 | // process all integer digits. |
| 2698 | const char* p = num.integer.ptr; |
| 2699 | const char* pend = p + num.integer.len(); |
| 2700 | skip_zeros(p, pend); |
| 2701 | // process all digits, in increments of step per loop |
| 2702 | while (p != pend) { |
| 2703 | while ((std::distance(p, pend) >= 8) && (step - counter >= 8) && (max_digits - digits >= 8)) { |
| 2704 | parse_eight_digits(p, value, counter, digits); |
| 2705 | } |
| 2706 | while (counter < step && p != pend && digits < max_digits) { |
| 2707 | parse_one_digit(p, value, counter, digits); |
| 2708 | } |
| 2709 | if (digits == max_digits) { |
| 2710 | // add the temporary value, then check if we've truncated any digits |
| 2711 | add_native(result, limb(powers_of_ten_uint64[counter]), value); |
| 2712 | bool truncated = is_truncated(p, pend); |
| 2713 | if (num.fraction.ptr != nullptr) { |
| 2714 | truncated |= is_truncated(num.fraction); |
| 2715 | } |
| 2716 | if (truncated) { |
| 2717 | round_up_bigint(result, digits); |
| 2718 | } |
| 2719 | return; |
| 2720 | } else { |
| 2721 | add_native(result, limb(powers_of_ten_uint64[counter]), value); |
| 2722 | counter = 0; |
| 2723 | value = 0; |
| 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | // add our fraction digits, if they're available. |
| 2728 | if (num.fraction.ptr != nullptr) { |
| 2729 | p = num.fraction.ptr; |
| 2730 | pend = p + num.fraction.len(); |
| 2731 | if (digits == 0) { |
| 2732 | skip_zeros(p, pend); |
| 2733 | } |
| 2734 | // process all digits, in increments of step per loop |
| 2735 | while (p != pend) { |
| 2736 | while ((std::distance(p, pend) >= 8) && (step - counter >= 8) && (max_digits - digits >= 8)) { |
| 2737 | parse_eight_digits(p, value, counter, digits); |
| 2738 | } |
| 2739 | while (counter < step && p != pend && digits < max_digits) { |
| 2740 | parse_one_digit(p, value, counter, digits); |
| 2741 | } |
no test coverage detected