20#include <xrpl/beast/unit_test.h>
21#include <xrpl/protocol/IOUAmount.h>
38 BEAST_EXPECT(z.
signum() == 0);
39 BEAST_EXPECT(z == beast::zero);
41 BEAST_EXPECT((z + z) == z);
42 BEAST_EXPECT((z - z) == z);
43 BEAST_EXPECT(z == -z);
46 BEAST_EXPECT(z == zz);
50 BEAST_EXPECT(zzz == beast::zero);
60 BEAST_EXPECT(neg.
signum() < 0);
63 BEAST_EXPECT(zer.
signum() == 0);
66 BEAST_EXPECT(pos.
signum() > 0);
78 BEAST_EXPECT(z == zero);
79 BEAST_EXPECT(z >= zero);
80 BEAST_EXPECT(z <= zero);
88 BEAST_EXPECT(neg < zero);
89 BEAST_EXPECT(neg <= zero);
90 BEAST_EXPECT(neg != zero);
96 BEAST_EXPECT(pos > zero);
97 BEAST_EXPECT(pos >= zero);
98 BEAST_EXPECT(pos != zero);
112 BEAST_EXPECT(z == z);
113 BEAST_EXPECT(z >= z);
114 BEAST_EXPECT(z <= z);
115 BEAST_EXPECT(z == -z);
122 BEAST_EXPECT(n <= z);
123 BEAST_EXPECT(n != z);
129 BEAST_EXPECT(p >= z);
130 BEAST_EXPECT(p != z);
136 BEAST_EXPECT(n <= p);
137 BEAST_EXPECT(n != p);
143 BEAST_EXPECT(p >= n);
144 BEAST_EXPECT(p != n);
149 BEAST_EXPECT(p > -p);
150 BEAST_EXPECT(p >= -p);
151 BEAST_EXPECT(p != -p);
153 BEAST_EXPECT(n < -n);
154 BEAST_EXPECT(n <= -n);
155 BEAST_EXPECT(n != -n);
192 BEAST_EXPECT(bigMan ==
mulRatio(bigMan, maxUInt, maxUInt,
true));
194 BEAST_EXPECT(bigMan ==
mulRatio(bigMan, maxUInt, maxUInt,
false));
199 BEAST_EXPECT(bigMan ==
mulRatio(bigMan, maxUInt, maxUInt,
true));
201 BEAST_EXPECT(bigMan ==
mulRatio(bigMan, maxUInt, maxUInt,
false));
208 BEAST_EXPECT(tiny ==
mulRatio(tiny, 1, maxUInt,
true));
209 BEAST_EXPECT(tiny ==
mulRatio(tiny, maxUInt - 1, maxUInt,
true));
211 BEAST_EXPECT(beast::zero ==
mulRatio(tiny, 1, maxUInt,
false));
213 beast::zero ==
mulRatio(tiny, maxUInt - 1, maxUInt,
false));
218 BEAST_EXPECT(beast::zero ==
mulRatio(tinyNeg, 1, maxUInt,
true));
220 beast::zero ==
mulRatio(tinyNeg, maxUInt - 1, maxUInt,
true));
222 BEAST_EXPECT(tinyNeg ==
mulRatio(tinyNeg, 1, maxUInt,
false));
224 tinyNeg ==
mulRatio(tinyNeg, maxUInt - 1, maxUInt,
false));
230 auto const rup =
mulRatio(
one, maxUInt - 1, maxUInt,
true);
231 auto const rdown =
mulRatio(
one, maxUInt - 1, maxUInt,
false);
232 BEAST_EXPECT(rup.mantissa() - rdown.mantissa() == 1);
236 auto const rup =
mulRatio(big, maxUInt - 1, maxUInt,
true);
237 auto const rdown =
mulRatio(big, maxUInt - 1, maxUInt,
false);
238 BEAST_EXPECT(rup.mantissa() - rdown.mantissa() == 1);
243 auto const rup =
mulRatio(negOne, maxUInt - 1, maxUInt,
true);
245 mulRatio(negOne, maxUInt - 1, maxUInt,
false);
246 BEAST_EXPECT(rup.mantissa() - rdown.mantissa() == 1);
bool unexpected(Condition shouldBeFalse, String const &reason)
testcase_t testcase
Memberspace for declaring test cases.
bool except(F &&f, String const &reason)
void run() override
Runs the suite.
Floating point representation of amounts with high dynamic range.
int exponent() const noexcept
int signum() const noexcept
Return the sign of the amount.
std::int64_t mantissa() const noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static int constexpr maxExponent
static int constexpr minExponent
static std::int64_t constexpr maxMantissa
static std::int64_t constexpr minMantissa
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
std::string to_string(base_uint< Bits, Tag > const &a)