Skip to content

Commit b9d91e7

Browse files
committed
* code cleanup.
1 parent e109eed commit b9d91e7

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

include/fast_float/bigint.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -535,19 +535,17 @@ struct bigint : pow5_tables<> {
535535
// we can't shift more than the capacity of the vector.
536536
return false;
537537
}
538-
if (vec.is_empty()) {
539-
// nothing to do
540-
return true;
538+
if (!vec.is_empty()) {
539+
// move limbs
540+
limb *dst = vec.data + n;
541+
limb const *src = vec.data;
542+
std::copy_backward(src, src + vec.len(), dst + vec.len());
543+
// fill in empty limbs
544+
limb *first = vec.data;
545+
limb *last = first + n;
546+
::std::fill(first, last, 0);
547+
vec.set_len(limb_t(n + vec.len()));
541548
}
542-
// move limbs
543-
limb *dst = vec.data + n;
544-
limb const *src = vec.data;
545-
std::copy_backward(src, src + vec.len(), dst + vec.len());
546-
// fill in empty limbs
547-
limb *first = vec.data;
548-
limb *last = first + n;
549-
::std::fill(first, last, 0);
550-
vec.set_len(limb_t(n + vec.len()));
551549
return true;
552550
}
553551

@@ -590,12 +588,14 @@ struct bigint : pow5_tables<> {
590588
FASTFLOAT_CONSTEXPR20 bool add(limb y) noexcept { return small_add(vec, y); }
591589

592590
// multiply as if by 2 raised to a power.
593-
FASTFLOAT_CONSTEXPR20 bool pow2(am_pow_t exp) noexcept {
591+
FASTFLOAT_CONSTEXPR20 bool pow2(am_pow_t const exp) noexcept {
592+
FASTFLOAT_ASSERT(exp >= 0);
594593
return shl(static_cast<fast_float::bigint_bits_t>(exp));
595594
}
596595

597596
// multiply as if by 5 raised to a power.
598597
FASTFLOAT_CONSTEXPR20 bool pow5(am_pow_t exp) noexcept {
598+
FASTFLOAT_ASSERT(exp >= 0);
599599
// multiply by a power of 5
600600
limb_t const large_length = sizeof(large_power_of_5) / sizeof(limb);
601601
limb_span const large = limb_span(large_power_of_5, large_length);
@@ -627,6 +627,7 @@ struct bigint : pow5_tables<> {
627627

628628
// multiply as if by 10 raised to a power.
629629
FASTFLOAT_CONSTEXPR20 bool pow10(am_pow_t exp) noexcept {
630+
FASTFLOAT_ASSERT(exp >= 0);
630631
FASTFLOAT_TRY(pow5(exp));
631632
return pow2(exp);
632633
}

include/fast_float/digit_comparison.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,9 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa positive_digit_comp(
373373
// we then need to scale by `2^(f- e)`, and then the two significant digits
374374
// are of the same magnitude.
375375
template <typename T>
376-
inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp(
377-
bigint &bigmant, adjusted_mantissa am, am_pow_t const exponent) noexcept {
378-
bigint &real_digits = bigmant;
379-
am_pow_t const &real_exp = exponent;
380-
376+
inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
377+
negative_digit_comp(bigint &real_digits, adjusted_mantissa am,
378+
am_pow_t const real_exp) noexcept {
381379
// get the value of `b`, rounded down, and get a bigint representation of
382380
// b+h
383381
adjusted_mantissa am_b = am;
@@ -391,12 +389,12 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp(
391389
false,
392390
#endif
393391
am_b, b);
394-
adjusted_mantissa theor = to_extended_halfway(b);
392+
adjusted_mantissa const theor = to_extended_halfway(b);
395393
bigint theor_digits(theor.mantissa);
396-
am_pow_t theor_exp = theor.power2;
394+
am_pow_t const theor_exp = theor.power2;
397395

398396
// scale real digits and theor digits to be same power.
399-
am_pow_t pow2_exp = theor_exp - real_exp;
397+
am_pow_t const pow2_exp = theor_exp - real_exp;
400398
am_pow_t pow5_exp = -real_exp;
401399
if (pow5_exp != 0) {
402400
FASTFLOAT_ASSERT(theor_digits.pow5(pow5_exp));
@@ -408,7 +406,7 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp(
408406
}
409407

410408
// compare digits, and use it to direct rounding
411-
int ord = real_digits.compare(theor_digits);
409+
int const ord = real_digits.compare(theor_digits);
412410
round<T>(am, [ord](adjusted_mantissa &a, am_pow_t shift) {
413411
round_nearest_tie_even(
414412
a, shift, [ord](bool is_odd, bool _, bool __) -> bool {

0 commit comments

Comments
 (0)