From a4aa72eada60c4d0aaf90ead3d2d62b3c0c9136e Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Wed, 12 Nov 2025 19:19:06 -0500 Subject: [PATCH] Fix revert issues --- include/xrpl/basics/Number.h | 13 ++++++++++++- include/xrpl/protocol/Asset.h | 6 ++++++ include/xrpl/protocol/STAmount.h | 9 +++++++++ src/test/basics/Number_test.cpp | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/xrpl/basics/Number.h b/include/xrpl/basics/Number.h index 080a807909..4a4ee1cacb 100644 --- a/include/xrpl/basics/Number.h +++ b/include/xrpl/basics/Number.h @@ -13,6 +13,15 @@ class Number; std::string to_string(Number const& amount); +template +constexpr bool +isPowerOfTen(T value) +{ + while (value >= 10 && value % 10 == 0) + value /= 10; + return value == 1; +} + class Number { using rep = std::int64_t; @@ -22,7 +31,9 @@ class Number public: // The range for the mantissa when normalized 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 constexpr static int minExponent = -32768; diff --git a/include/xrpl/protocol/Asset.h b/include/xrpl/protocol/Asset.h index d0efe814a9..6765f7cf7d 100644 --- a/include/xrpl/protocol/Asset.h +++ b/include/xrpl/protocol/Asset.h @@ -84,6 +84,12 @@ public: return holds() && get().native(); } + bool + integral() const + { + return !holds() || get().native(); + } + friend constexpr bool operator==(Asset const& lhs, Asset const& rhs); diff --git a/include/xrpl/protocol/STAmount.h b/include/xrpl/protocol/STAmount.h index d12e218250..f3f285249c 100644 --- a/include/xrpl/protocol/STAmount.h +++ b/include/xrpl/protocol/STAmount.h @@ -157,6 +157,9 @@ public: int exponent() const noexcept; + bool + integral() const noexcept; + bool native() const noexcept; @@ -437,6 +440,12 @@ STAmount::exponent() const noexcept return mOffset; } +inline bool +STAmount::integral() const noexcept +{ + return mAsset.integral(); +} + inline bool STAmount::native() const noexcept { diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index cec69fe05f..bb5262d028 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -834,6 +834,7 @@ public: } } + void run() override { testZero();