mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-23 15:20:54 +00:00
Clean-ups and tweaks
This commit is contained in:
@@ -632,7 +632,7 @@ private:
|
||||
|
||||
/** Breaks down the number into components, potentially de-normalizing it.
|
||||
*
|
||||
* Ensures that the mantissa always has range_.log digits.
|
||||
* Ensures that the mantissa always has range_.log + 1 digits.
|
||||
*
|
||||
*/
|
||||
template <detail::UnsignedMantissa Rep = internalrep>
|
||||
@@ -641,7 +641,7 @@ private:
|
||||
|
||||
/** Breaks down the number into components, potentially de-normalizing it.
|
||||
*
|
||||
* Ensures that the mantissa always has range_.log digits.
|
||||
* Ensures that the mantissa always has range_.log + 1 digits.
|
||||
*
|
||||
*/
|
||||
template <detail::UnsignedMantissa Rep = internalrep>
|
||||
|
||||
@@ -293,7 +293,8 @@ Number::Guard::doRound(rep& drops, std::string_view location)
|
||||
auto r = round();
|
||||
if (r == 1 || (r == 0 && (drops & 1) == 1))
|
||||
{
|
||||
if (drops >= maxMantissa())
|
||||
auto const& range = range_.get();
|
||||
if (drops >= range.max)
|
||||
{
|
||||
static_assert(sizeof(internalrep) == sizeof(rep));
|
||||
// This should be impossible, because it's impossible to represent
|
||||
@@ -1120,7 +1121,7 @@ Number::root(MantissaRange const& range, Number f, unsigned d)
|
||||
|
||||
// Scale f into the range (0, 1) such that the scale change (e) is a
|
||||
// multiple of the root (d)
|
||||
auto e = exponent + Number::mantissaLog() + 1;
|
||||
auto e = exponent + range.log + 1;
|
||||
auto const di = static_cast<int>(d);
|
||||
auto ex = [e = e, di = di]() // Euclidean remainder of e/d
|
||||
{
|
||||
@@ -1213,7 +1214,7 @@ root2(Number f)
|
||||
|
||||
// Scale f into the range (0, 1) such that f's exponent is a
|
||||
// multiple of d
|
||||
auto e = exponent + Number::mantissaLog() + 1;
|
||||
auto e = exponent + range.log + 1;
|
||||
if (e % 2 != 0)
|
||||
++e;
|
||||
f = f.shiftExponent(-e); // f /= 10^e;
|
||||
|
||||
@@ -228,6 +228,25 @@ public:
|
||||
// result will overflow. With addition using uint128_t,
|
||||
// there's no problem. After normalizing, the resulting
|
||||
// mantissa ends up less than largestMantissa.
|
||||
Number{
|
||||
false,
|
||||
Number::largestMantissa,
|
||||
0,
|
||||
Number::normalized{}},
|
||||
Number{
|
||||
false,
|
||||
Number::largestMantissa,
|
||||
0,
|
||||
Number::normalized{}},
|
||||
Number{
|
||||
false,
|
||||
Number::largestMantissa * 2,
|
||||
0,
|
||||
Number::normalized{}},
|
||||
},
|
||||
{
|
||||
// These mantissas round down, so adding them together won't
|
||||
// have any consequences.
|
||||
Number{
|
||||
false,
|
||||
9'999'999'999'999'999'990ULL,
|
||||
@@ -604,7 +623,6 @@ public:
|
||||
Number::normalized{}},
|
||||
__LINE__},
|
||||
// Maximum actual mantissa range - same as int64
|
||||
// 99'999'999'999'999'999'800'000'000'000'000'000'100
|
||||
{Number{false, maxMantissa, 0, Number::normalized{}},
|
||||
Number{false, maxMantissa, 0, Number::normalized{}},
|
||||
Number{85'070'591'730'234'615'84, 19},
|
||||
|
||||
Reference in New Issue
Block a user