MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / parse_mantissa

Function parse_mantissa

Source/external/fast_float.h:2920–2998  ·  view source on GitHub ↗

parse the significant digits into a big integer

Source from the content-addressed store, hash-verified

2918
2919// parse the significant digits into a big integer
2920inline FASTFLOAT_CONSTEXPR20
2921void parse_mantissa(bigint& result, parsed_number_string& num, size_t max_digits, size_t& digits) noexcept {
2922 // try to minimize the number of big integer and scalar multiplication.
2923 // therefore, try to parse 8 digits at a time, and multiply by the largest
2924 // scalar value (9 or 19 digits) for each step.
2925 size_t counter = 0;
2926 digits = 0;
2927 limb value = 0;
2928#ifdef FASTFLOAT_64BIT_LIMB
2929 size_t step = 19;
2930#else
2931 size_t step = 9;
2932#endif
2933
2934 // process all integer digits.
2935 const char* p = num.integer.ptr;
2936 const char* pend = p + num.integer.len();
2937 skip_zeros(p, pend);
2938 // process all digits, in increments of step per loop
2939 while (p != pend) {
2940 while ((std::distance(p, pend) >= 8) && (step - counter >= 8) && (max_digits - digits >= 8)) {
2941 parse_eight_digits(p, value, counter, digits);
2942 }
2943 while (counter < step && p != pend && digits < max_digits) {
2944 parse_one_digit(p, value, counter, digits);
2945 }
2946 if (digits == max_digits) {
2947 // add the temporary value, then check if we've truncated any digits
2948 add_native(result, limb(powers_of_ten_uint64[counter]), value);
2949 bool truncated = is_truncated(p, pend);
2950 if (num.fraction.ptr != nullptr) {
2951 truncated |= is_truncated(num.fraction);
2952 }
2953 if (truncated) {
2954 round_up_bigint(result, digits);
2955 }
2956 return;
2957 } else {
2958 add_native(result, limb(powers_of_ten_uint64[counter]), value);
2959 counter = 0;
2960 value = 0;
2961 }
2962 }
2963
2964 // add our fraction digits, if they're available.
2965 if (num.fraction.ptr != nullptr) {
2966 p = num.fraction.ptr;
2967 pend = p + num.fraction.len();
2968 if (digits == 0) {
2969 skip_zeros(p, pend);
2970 }
2971 // process all digits, in increments of step per loop
2972 while (p != pend) {
2973 while ((std::distance(p, pend) >= 8) && (step - counter >= 8) && (max_digits - digits >= 8)) {
2974 parse_eight_digits(p, value, counter, digits);
2975 }
2976 while (counter < step && p != pend && digits < max_digits) {
2977 parse_one_digit(p, value, counter, digits);

Callers 1

Calls 7

skip_zerosFunction · 0.85
parse_eight_digitsFunction · 0.85
parse_one_digitFunction · 0.85
add_nativeFunction · 0.85
is_truncatedFunction · 0.85
round_up_bigintFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected