mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-08 03:07:13 +00:00
Merge branch 'ximinez/number-round-maxrep-down' into ximinez/number-round-maxrep
* ximinez/number-round-maxrep-down: Revert "Rollback Number class changes; show the fix works without side effects" Rollback Number class changes; show the fix works without side effects Include rounding in failed unit tests Improve comment descriptions Rework subtraction rounding (again) for more accuracy build: Create single test binary xrpl_tests (7327) ci: [DEPENDABOT] bump actions/checkout from 6.0.2 to 6.0.3 (7414) ci: Refactor build-related nix / docker / workflows (7408) refactor: Construct Number::Guard from MantissaRange or relevant fields ci: Use multiple directories in dependabot config (7413) ci: Update clang-tidy to nix-based v22 (7412) clang-tidy: template param names, const correctness, braces
This commit is contained in:
@@ -54,11 +54,11 @@ namespace detail {
|
||||
constexpr std::size_t kUint64Digits = 20;
|
||||
constexpr std::size_t kUint128Digits = 39;
|
||||
|
||||
template <typename T, std::size_t digits>
|
||||
consteval std::array<T, digits>
|
||||
template <typename T, std::size_t Digits>
|
||||
consteval std::array<T, Digits>
|
||||
buildPowersOfTen()
|
||||
{
|
||||
std::array<T, digits> result{};
|
||||
std::array<T, Digits> result{};
|
||||
|
||||
T power = 1;
|
||||
std::size_t exponent = 0;
|
||||
@@ -78,8 +78,8 @@ buildPowersOfTen()
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T = std::uint64_t, std::size_t digits = detail::kUint64Digits>
|
||||
constexpr std::array<T, digits> kPowerOfTenImpl = detail::buildPowersOfTen<T, digits>();
|
||||
template <typename T = std::uint64_t, std::size_t Digits = detail::kUint64Digits>
|
||||
constexpr std::array<T, Digits> kPowerOfTenImpl = detail::buildPowersOfTen<T, Digits>();
|
||||
|
||||
constexpr auto kPowerOfTen = kPowerOfTenImpl<std::uint64_t, detail::kUint64Digits>;
|
||||
|
||||
@@ -551,9 +551,15 @@ private:
|
||||
// changing the values inside the range.
|
||||
static thread_local std::reference_wrapper<MantissaRange const> kRange;
|
||||
|
||||
class Guard;
|
||||
|
||||
void
|
||||
normalize(MantissaRange const& range);
|
||||
|
||||
// Guard has the fields that we need, as well as MantissaRange, so if we have a guard, use that
|
||||
void
|
||||
normalize(Guard const& guard);
|
||||
|
||||
/** Normalize Number components to an arbitrary range.
|
||||
*
|
||||
* min/maxMantissa are parameters because this function is used by both
|
||||
@@ -596,8 +602,6 @@ private:
|
||||
// UB, and can vary across compilers.
|
||||
static internalrep
|
||||
externalToInternal(rep mantissa);
|
||||
|
||||
class Guard;
|
||||
};
|
||||
|
||||
constexpr Number::Number(bool negative, internalrep mantissa, int exponent, Unchecked) noexcept
|
||||
@@ -875,6 +879,26 @@ to_string(MantissaRange::MantissaScale const& scale)
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string
|
||||
to_string(Number::RoundingMode const& round)
|
||||
{
|
||||
switch (round)
|
||||
{
|
||||
enum class RoundingMode { ToNearest, TowardsZero, Downward, Upward };
|
||||
|
||||
case Number::RoundingMode::ToNearest:
|
||||
return "ToNearest";
|
||||
case Number::RoundingMode::TowardsZero:
|
||||
return "TowardsZero";
|
||||
case Number::RoundingMode::Downward:
|
||||
return "Downward";
|
||||
case Number::RoundingMode::Upward:
|
||||
return "Upward";
|
||||
default:
|
||||
throw std::runtime_error("Bad rounding mode");
|
||||
}
|
||||
}
|
||||
|
||||
class SaveNumberRoundMode
|
||||
{
|
||||
Number::RoundingMode mode_;
|
||||
|
||||
@@ -25,7 +25,7 @@ struct varint_traits<T, true>
|
||||
{
|
||||
explicit varint_traits() = default;
|
||||
|
||||
static constexpr std::size_t kMax = (8 * sizeof(T) + 6) / 7;
|
||||
static constexpr std::size_t kMax = ((8 * sizeof(T)) + 6) / 7;
|
||||
};
|
||||
|
||||
// Returns: Number of bytes consumed or 0 on error,
|
||||
|
||||
Reference in New Issue
Block a user