mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
* code cleanup.
This commit is contained in:
parent
e109eedd35
commit
b9d91e7f34
@ -535,19 +535,17 @@ struct bigint : pow5_tables<> {
|
|||||||
// we can't shift more than the capacity of the vector.
|
// we can't shift more than the capacity of the vector.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (vec.is_empty()) {
|
if (!vec.is_empty()) {
|
||||||
// nothing to do
|
// move limbs
|
||||||
return true;
|
limb *dst = vec.data + n;
|
||||||
|
limb const *src = vec.data;
|
||||||
|
std::copy_backward(src, src + vec.len(), dst + vec.len());
|
||||||
|
// fill in empty limbs
|
||||||
|
limb *first = vec.data;
|
||||||
|
limb *last = first + n;
|
||||||
|
::std::fill(first, last, 0);
|
||||||
|
vec.set_len(limb_t(n + vec.len()));
|
||||||
}
|
}
|
||||||
// move limbs
|
|
||||||
limb *dst = vec.data + n;
|
|
||||||
limb const *src = vec.data;
|
|
||||||
std::copy_backward(src, src + vec.len(), dst + vec.len());
|
|
||||||
// fill in empty limbs
|
|
||||||
limb *first = vec.data;
|
|
||||||
limb *last = first + n;
|
|
||||||
::std::fill(first, last, 0);
|
|
||||||
vec.set_len(limb_t(n + vec.len()));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -590,12 +588,14 @@ struct bigint : pow5_tables<> {
|
|||||||
FASTFLOAT_CONSTEXPR20 bool add(limb y) noexcept { return small_add(vec, y); }
|
FASTFLOAT_CONSTEXPR20 bool add(limb y) noexcept { return small_add(vec, y); }
|
||||||
|
|
||||||
// multiply as if by 2 raised to a power.
|
// multiply as if by 2 raised to a power.
|
||||||
FASTFLOAT_CONSTEXPR20 bool pow2(am_pow_t exp) noexcept {
|
FASTFLOAT_CONSTEXPR20 bool pow2(am_pow_t const exp) noexcept {
|
||||||
|
FASTFLOAT_ASSERT(exp >= 0);
|
||||||
return shl(static_cast<fast_float::bigint_bits_t>(exp));
|
return shl(static_cast<fast_float::bigint_bits_t>(exp));
|
||||||
}
|
}
|
||||||
|
|
||||||
// multiply as if by 5 raised to a power.
|
// multiply as if by 5 raised to a power.
|
||||||
FASTFLOAT_CONSTEXPR20 bool pow5(am_pow_t exp) noexcept {
|
FASTFLOAT_CONSTEXPR20 bool pow5(am_pow_t exp) noexcept {
|
||||||
|
FASTFLOAT_ASSERT(exp >= 0);
|
||||||
// multiply by a power of 5
|
// multiply by a power of 5
|
||||||
limb_t const large_length = sizeof(large_power_of_5) / sizeof(limb);
|
limb_t const large_length = sizeof(large_power_of_5) / sizeof(limb);
|
||||||
limb_span const large = limb_span(large_power_of_5, large_length);
|
limb_span const large = limb_span(large_power_of_5, large_length);
|
||||||
@ -627,6 +627,7 @@ struct bigint : pow5_tables<> {
|
|||||||
|
|
||||||
// multiply as if by 10 raised to a power.
|
// multiply as if by 10 raised to a power.
|
||||||
FASTFLOAT_CONSTEXPR20 bool pow10(am_pow_t exp) noexcept {
|
FASTFLOAT_CONSTEXPR20 bool pow10(am_pow_t exp) noexcept {
|
||||||
|
FASTFLOAT_ASSERT(exp >= 0);
|
||||||
FASTFLOAT_TRY(pow5(exp));
|
FASTFLOAT_TRY(pow5(exp));
|
||||||
return pow2(exp);
|
return pow2(exp);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -373,11 +373,9 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa positive_digit_comp(
|
|||||||
// we then need to scale by `2^(f- e)`, and then the two significant digits
|
// we then need to scale by `2^(f- e)`, and then the two significant digits
|
||||||
// are of the same magnitude.
|
// are of the same magnitude.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp(
|
inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
|
||||||
bigint &bigmant, adjusted_mantissa am, am_pow_t const exponent) noexcept {
|
negative_digit_comp(bigint &real_digits, adjusted_mantissa am,
|
||||||
bigint &real_digits = bigmant;
|
am_pow_t const real_exp) noexcept {
|
||||||
am_pow_t const &real_exp = exponent;
|
|
||||||
|
|
||||||
// get the value of `b`, rounded down, and get a bigint representation of
|
// get the value of `b`, rounded down, and get a bigint representation of
|
||||||
// b+h
|
// b+h
|
||||||
adjusted_mantissa am_b = am;
|
adjusted_mantissa am_b = am;
|
||||||
@ -391,12 +389,12 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp(
|
|||||||
false,
|
false,
|
||||||
#endif
|
#endif
|
||||||
am_b, b);
|
am_b, b);
|
||||||
adjusted_mantissa theor = to_extended_halfway(b);
|
adjusted_mantissa const theor = to_extended_halfway(b);
|
||||||
bigint theor_digits(theor.mantissa);
|
bigint theor_digits(theor.mantissa);
|
||||||
am_pow_t theor_exp = theor.power2;
|
am_pow_t const theor_exp = theor.power2;
|
||||||
|
|
||||||
// scale real digits and theor digits to be same power.
|
// scale real digits and theor digits to be same power.
|
||||||
am_pow_t pow2_exp = theor_exp - real_exp;
|
am_pow_t const pow2_exp = theor_exp - real_exp;
|
||||||
am_pow_t pow5_exp = -real_exp;
|
am_pow_t pow5_exp = -real_exp;
|
||||||
if (pow5_exp != 0) {
|
if (pow5_exp != 0) {
|
||||||
FASTFLOAT_ASSERT(theor_digits.pow5(pow5_exp));
|
FASTFLOAT_ASSERT(theor_digits.pow5(pow5_exp));
|
||||||
@ -408,7 +406,7 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// compare digits, and use it to direct rounding
|
// compare digits, and use it to direct rounding
|
||||||
int ord = real_digits.compare(theor_digits);
|
int const ord = real_digits.compare(theor_digits);
|
||||||
round<T>(am, [ord](adjusted_mantissa &a, am_pow_t shift) {
|
round<T>(am, [ord](adjusted_mantissa &a, am_pow_t shift) {
|
||||||
round_nearest_tie_even(
|
round_nearest_tie_even(
|
||||||
a, shift, [ord](bool is_odd, bool _, bool __) -> bool {
|
a, shift, [ord](bool is_odd, bool _, bool __) -> bool {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user