MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / parse_mantissa

Function parse_mantissa

app/src/ThirdParty/fast_float.h:4289–4370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4287// parse the significant digits into a big integer
4288template <typename UC>
4289inline FASTFLOAT_CONSTEXPR20 void
4290parse_mantissa(bigint &result, parsed_number_string_t<UC> &num,
4291 size_t max_digits, size_t &digits) noexcept {
4292 // try to minimize the number of big integer and scalar multiplication.
4293 // therefore, try to parse 8 digits at a time, and multiply by the largest
4294 // scalar value (9 or 19 digits) for each step.
4295 size_t counter = 0;
4296 digits = 0;
4297 limb value = 0;
4298#ifdef FASTFLOAT_64BIT_LIMB
4299 size_t step = 19;
4300#else
4301 size_t step = 9;
4302#endif
4303
4304 // process all integer digits.
4305 UC const *p = num.integer.ptr;
4306 UC const *pend = p + num.integer.len();
4307 skip_zeros(p, pend);
4308 // process all digits, in increments of step per loop
4309 while (p != pend) {
4310 while ((std::distance(p, pend) >= 8) && (step - counter >= 8) &&
4311 (max_digits - digits >= 8)) {
4312 parse_eight_digits(p, value, counter, digits);
4313 }
4314 while (counter < step && p != pend && digits < max_digits) {
4315 parse_one_digit(p, value, counter, digits);
4316 }
4317 if (digits == max_digits) {
4318 // add the temporary value, then check if we've truncated any digits
4319 add_native(result, limb(powers_of_ten_uint64[counter]), value);
4320 bool truncated = is_truncated(p, pend);
4321 if (num.fraction.ptr != nullptr) {
4322 truncated |= is_truncated(num.fraction);
4323 }
4324 if (truncated) {
4325 round_up_bigint(result, digits);
4326 }
4327 return;
4328 } else {
4329 add_native(result, limb(powers_of_ten_uint64[counter]), value);
4330 counter = 0;
4331 value = 0;
4332 }
4333 }
4334
4335 // add our fraction digits, if they're available.
4336 if (num.fraction.ptr != nullptr) {
4337 p = num.fraction.ptr;
4338 pend = p + num.fraction.len();
4339 if (digits == 0) {
4340 skip_zeros(p, pend);
4341 }
4342 // process all digits, in increments of step per loop
4343 while (p != pend) {
4344 while ((std::distance(p, pend) >= 8) && (step - counter >= 8) &&
4345 (max_digits - digits >= 8)) {
4346 parse_eight_digits(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