Skip to content

Commit a36d94b

Browse files
committed
unrelated changes leftover from development
1 parent 7b8f045 commit a36d94b

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

include/fast_float/ascii_number.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,23 @@ enum class parse_error {
251251
missing_exponential_part,
252252
};
253253

254-
template <typename UC> struct parsed_number_string_t {
254+
struct parsed_number_string_base_t {
255255
int64_t exponent{0};
256256
uint64_t mantissa{0};
257-
UC const *lastmatch{nullptr};
258257
bool negative{false};
258+
// the rest below is here because it does not depend on template parameters
259+
// and because it packs nicely
259260
bool valid{false};
260261
bool too_many_digits{false};
262+
parse_error error{parse_error::no_error};
263+
};
264+
265+
template <typename UC>
266+
struct parsed_number_string_t : parsed_number_string_base_t {
267+
UC const *lastmatch{nullptr};
261268
// contains the range of the significant digits
262269
span<UC const> integer{}; // non-nullable
263270
span<UC const> fraction{}; // nullable
264-
parse_error error{parse_error::no_error};
265271
};
266272

267273
using byte_span = span<char const>;

include/fast_float/digit_comparison.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ constexpr static uint64_t powers_of_ten_uint64[] = {1UL,
3838
// this algorithm is not even close to optimized, but it has no practical
3939
// effect on performance: in order to have a faster algorithm, we'd need
4040
// to slow down performance for faster algorithms, and this is still fast.
41-
template <typename UC>
4241
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 int32_t
43-
scientific_exponent(parsed_number_string_t<UC> &num) noexcept {
44-
uint64_t mantissa = num.mantissa;
45-
int32_t exponent = int32_t(num.exponent);
42+
scientific_exponent(uint64_t mantissa, int32_t exponent) noexcept {
4643
while (mantissa >= 10000) {
4744
mantissa /= 10000;
4845
exponent += 4;
@@ -398,7 +395,7 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp(
398395
FASTFLOAT_ASSERT(real_digits.pow2(uint32_t(-pow2_exp)));
399396
}
400397

401-
// compare digits, and use it to director rounding
398+
// compare digits, and use it to direct rounding
402399
int ord = real_digits.compare(theor_digits);
403400
adjusted_mantissa answer = am;
404401
round<T>(answer, [ord](adjusted_mantissa &a, int32_t shift) {
@@ -419,7 +416,7 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp(
419416
return answer;
420417
}
421418

422-
// parse the significant digits as a big integer to unambiguously round the
419+
// parse the significant digits as a big integer to unambiguously round
423420
// the significant digits. here, we are trying to determine how to round
424421
// an extended float representation close to `b+h`, halfway between `b`
425422
// (the float rounded-down) and `b+u`, the next positive float. this
@@ -438,7 +435,8 @@ digit_comp(parsed_number_string_t<UC> &num, adjusted_mantissa am) noexcept {
438435
// remove the invalid exponent bias
439436
am.power2 -= invalid_am_bias;
440437

441-
int32_t sci_exp = scientific_exponent(num);
438+
int32_t sci_exp =
439+
scientific_exponent(num.mantissa, static_cast<int32_t>(num.exponent));
442440
size_t max_digits = binary_format<T>::max_digits();
443441
size_t digits = 0;
444442
bigint bigmant;

0 commit comments

Comments
 (0)