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);
55 BEAST_EXPECT(neg.
signum() < 0);
58 BEAST_EXPECT(zer.
signum() == 0);
61 BEAST_EXPECT(pos.
signum() > 0);
73 BEAST_EXPECT(z == zero);
74 BEAST_EXPECT(z >= zero);
75 BEAST_EXPECT(z <= zero);
83 BEAST_EXPECT(neg < zero);
84 BEAST_EXPECT(neg <= zero);
85 BEAST_EXPECT(neg != zero);
91 BEAST_EXPECT(pos > zero);
92 BEAST_EXPECT(pos >= zero);
93 BEAST_EXPECT(pos != zero);
107 BEAST_EXPECT(z == z);
108 BEAST_EXPECT(z >= z);
109 BEAST_EXPECT(z <= z);
110 BEAST_EXPECT(z == -z);
117 BEAST_EXPECT(n <= z);
118 BEAST_EXPECT(n != z);
124 BEAST_EXPECT(p >= z);
125 BEAST_EXPECT(p != z);
131 BEAST_EXPECT(n <= p);
132 BEAST_EXPECT(n != p);
138 BEAST_EXPECT(p >= n);
139 BEAST_EXPECT(p != n);
144 BEAST_EXPECT(p > -p);
145 BEAST_EXPECT(p >= -p);
146 BEAST_EXPECT(p != -p);
148 BEAST_EXPECT(n < -n);
149 BEAST_EXPECT(n <= -n);
150 BEAST_EXPECT(n != -n);
187 BEAST_EXPECT(bigMan ==
mulRatio(bigMan, maxUInt, maxUInt,
true));
189 BEAST_EXPECT(bigMan ==
mulRatio(bigMan, maxUInt, maxUInt,
false));
194 BEAST_EXPECT(bigMan ==
mulRatio(bigMan, maxUInt, maxUInt,
true));
196 BEAST_EXPECT(bigMan ==
mulRatio(bigMan, maxUInt, maxUInt,
false));
203 BEAST_EXPECT(tiny ==
mulRatio(tiny, 1, maxUInt,
true));
204 BEAST_EXPECT(tiny ==
mulRatio(tiny, maxUInt - 1, maxUInt,
true));
206 BEAST_EXPECT(beast::zero ==
mulRatio(tiny, 1, maxUInt,
false));
208 beast::zero ==
mulRatio(tiny, maxUInt - 1, maxUInt,
false));
213 BEAST_EXPECT(beast::zero ==
mulRatio(tinyNeg, 1, maxUInt,
true));
215 beast::zero ==
mulRatio(tinyNeg, maxUInt - 1, maxUInt,
true));
217 BEAST_EXPECT(tinyNeg ==
mulRatio(tinyNeg, 1, maxUInt,
false));
219 tinyNeg ==
mulRatio(tinyNeg, maxUInt - 1, maxUInt,
false));
225 auto const rup =
mulRatio(
one, maxUInt - 1, maxUInt,
true);
226 auto const rdown =
mulRatio(
one, maxUInt - 1, maxUInt,
false);
227 BEAST_EXPECT(rup.mantissa() - rdown.mantissa() == 1);
231 auto const rup =
mulRatio(big, maxUInt - 1, maxUInt,
true);
232 auto const rdown =
mulRatio(big, maxUInt - 1, maxUInt,
false);
233 BEAST_EXPECT(rup.mantissa() - rdown.mantissa() == 1);
238 auto const rup =
mulRatio(negOne, maxUInt - 1, maxUInt,
true);
240 mulRatio(negOne, maxUInt - 1, maxUInt,
false);
241 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)