Fix revert issues

This commit is contained in:
Ed Hennis
2025-11-12 19:19:06 -05:00
parent 398170ef3d
commit a4aa72eada
4 changed files with 28 additions and 1 deletions

View File

@@ -13,6 +13,15 @@ class Number;
std::string std::string
to_string(Number const& amount); to_string(Number const& amount);
template <typename T>
constexpr bool
isPowerOfTen(T value)
{
while (value >= 10 && value % 10 == 0)
value /= 10;
return value == 1;
}
class Number class Number
{ {
using rep = std::int64_t; using rep = std::int64_t;
@@ -22,7 +31,9 @@ class Number
public: public:
// The range for the mantissa when normalized // The range for the mantissa when normalized
constexpr static std::int64_t minMantissa = 1'000'000'000'000'000LL; constexpr static std::int64_t minMantissa = 1'000'000'000'000'000LL;
constexpr static std::int64_t maxMantissa = 9'999'999'999'999'999LL; static_assert(isPowerOfTen(minMantissa));
constexpr static std::int64_t maxMantissa = minMantissa * 10 - 1;
static_assert(maxMantissa == 9'999'999'999'999'999LL);
// The range for the exponent when normalized // The range for the exponent when normalized
constexpr static int minExponent = -32768; constexpr static int minExponent = -32768;

View File

@@ -84,6 +84,12 @@ public:
return holds<Issue>() && get<Issue>().native(); return holds<Issue>() && get<Issue>().native();
} }
bool
integral() const
{
return !holds<Issue>() || get<Issue>().native();
}
friend constexpr bool friend constexpr bool
operator==(Asset const& lhs, Asset const& rhs); operator==(Asset const& lhs, Asset const& rhs);

View File

@@ -157,6 +157,9 @@ public:
int int
exponent() const noexcept; exponent() const noexcept;
bool
integral() const noexcept;
bool bool
native() const noexcept; native() const noexcept;
@@ -437,6 +440,12 @@ STAmount::exponent() const noexcept
return mOffset; return mOffset;
} }
inline bool
STAmount::integral() const noexcept
{
return mAsset.integral();
}
inline bool inline bool
STAmount::native() const noexcept STAmount::native() const noexcept
{ {

View File

@@ -834,6 +834,7 @@ public:
} }
} }
void
run() override run() override
{ {
testZero(); testZero();