diff --git a/AccountDelete__test_8cpp_source.html b/AccountDelete__test_8cpp_source.html index bf04463e6a..6ce35478b0 100644 --- a/AccountDelete__test_8cpp_source.html +++ b/AccountDelete__test_8cpp_source.html @@ -1023,7 +1023,7 @@ $(function() {
ripple::test::jtx::balance
A balance matches.
Definition: balance.h:38
ripple::test::jtx::trust
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition: trust.cpp:30
ripple::test::AccountDelete_test::testWithTickets
void testWithTickets()
Definition: AccountDelete_test.cpp:809
-
ripple::STAmount::getJson
Json::Value getJson(JsonOptions) const override
Definition: STAmount.cpp:634
+
ripple::STAmount::getJson
Json::Value getJson(JsonOptions) const override
Definition: STAmount.cpp:655
std::chrono::duration
ripple::test::jtx::offer_cancel
Json::Value offer_cancel(Account const &account, std::uint32_t offerSeq)
Cancel an offer.
Definition: offer.cpp:45
ripple::tecDST_TAG_NEEDED
@ tecDST_TAG_NEEDED
Definition: TER.h:276
diff --git a/AccountLines_8cpp_source.html b/AccountLines_8cpp_source.html index 69014f59bd..951ed9de05 100644 --- a/AccountLines_8cpp_source.html +++ b/AccountLines_8cpp_source.html @@ -339,7 +339,7 @@ $(function() {
Json::arrayValue
@ arrayValue
array value (ordered list)
Definition: json_value.h:42
ripple::RPC::Context::loadType
Resource::Charge & loadType
Definition: Context.h:43
std::vector
STL class.
-
ripple::STAmount::getText
std::string getText() const override
Definition: STAmount.cpp:550
+
ripple::STAmount::getText
std::string getText() const override
Definition: STAmount.cpp:571
ripple::Issue::currency
Currency currency
Definition: Issue.h:37
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:104
ripple::RPCTrustLine
Definition: TrustLine.h:204
diff --git a/AccountOffers_8cpp_source.html b/AccountOffers_8cpp_source.html index d462b8b03c..f46b055cdf 100644 --- a/AccountOffers_8cpp_source.html +++ b/AccountOffers_8cpp_source.html @@ -268,7 +268,7 @@ $(function() {
ripple::RPC::Context::loadType
Resource::Charge & loadType
Definition: Context.h:43
std::vector
STL class.
ripple::sfBookDirectory
const SF_UINT256 sfBookDirectory
-
ripple::STAmount::getText
std::string getText() const override
Definition: STAmount.cpp:550
+
ripple::STAmount::getText
std::string getText() const override
Definition: STAmount.cpp:571
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:104
std::stringstream
STL class.
ripple::RPC::lookupLedger
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext &context, Json::Value &result)
Look up a ledger from a request and fill a Json::Result with the data representing a ledger.
Definition: RPCHelpers.cpp:675
@@ -287,7 +287,7 @@ $(function() {
ripple::sfTakerGets
const SF_AMOUNT sfTakerGets
ripple::doAccountOffers
Json::Value doAccountOffers(RPC::JsonContext &context)
Definition: AccountOffers.cpp:57
std::uint64_t
-
ripple::amountFromQuality
STAmount amountFromQuality(std::uint64_t rate)
Definition: STAmount.cpp:831
+
ripple::amountFromQuality
STAmount amountFromQuality(std::uint64_t rate)
Definition: STAmount.cpp:852
ripple::ReadView::read
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::rpcACT_MALFORMED
@ rpcACT_MALFORMED
Definition: ErrorCodes.h:90
diff --git a/AmountSpec_8h_source.html b/AmountSpec_8h_source.html index f2227102eb..835c9c3d71 100644 --- a/AmountSpec_8h_source.html +++ b/AmountSpec_8h_source.html @@ -297,8 +297,8 @@ $(function() {
ripple::AmountSpec::iou
IOUAmount iou
Definition: AmountSpec.h:39
ripple::IOUAmount
Floating point representation of amounts with high dynamic range.
Definition: IOUAmount.h:43
ripple::get< IOUAmount >
IOUAmount & get< IOUAmount >(EitherAmount &amt)
Definition: AmountSpec.h:126
-
ripple::STAmount::iou
IOUAmount iou() const
Definition: STAmount.cpp:328
-
ripple::STAmount::xrp
XRPAmount xrp() const
Definition: STAmount.cpp:313
+
ripple::STAmount::iou
IOUAmount iou() const
Definition: STAmount.cpp:349
+
ripple::STAmount::xrp
XRPAmount xrp() const
Definition: STAmount.cpp:334
ripple::EitherAmount::EitherAmount
EitherAmount(XRPAmount const &a)
Definition: AmountSpec.h:82
ripple::STAmount::exponent
int exponent() const noexcept
Definition: STAmount.h:323
ripple::toAmountSpec
AmountSpec toAmountSpec(STAmount const &amt)
Definition: AmountSpec.h:165
diff --git a/BookChanges_8h_source.html b/BookChanges_8h_source.html index 88492f7bf9..a974874414 100644 --- a/BookChanges_8h_source.html +++ b/BookChanges_8h_source.html @@ -292,9 +292,9 @@ $(function() {
ripple::sfFinalFields
const SField sfFinalFields
ripple::noIssue
Issue const & noIssue()
Returns an asset specifier that represents no account and currency.
Definition: Issue.h:103
std::tuple
-
ripple::STAmount::iou
IOUAmount iou() const
Definition: STAmount.cpp:328
+
ripple::STAmount::iou
IOUAmount iou() const
Definition: STAmount.cpp:349
ripple::sfDeletedNode
const SField sfDeletedNode
-
ripple::STAmount::xrp
XRPAmount xrp() const
Definition: STAmount.cpp:313
+
ripple::STAmount::xrp
XRPAmount xrp() const
Definition: STAmount.cpp:334
ripple::divide
STAmount divide(STAmount const &amount, Rate const &rate)
Definition: Rate2.cpp:86
ripple::sfTakerPays
const SF_AMOUNT sfTakerPays
ripple::sfTransactionType
const SF_UINT16 sfTransactionType
diff --git a/BookStep_8cpp_source.html b/BookStep_8cpp_source.html index 4a8ed51e56..4b16c2394d 100644 --- a/BookStep_8cpp_source.html +++ b/BookStep_8cpp_source.html @@ -1260,7 +1260,7 @@ $(function() {
1196 
1197 } // namespace ripple
-
ripple::mulRatio
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
Definition: IOUAmount.cpp:161
+
ripple::mulRatio
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
Definition: IOUAmount.cpp:182
ripple::BookStep::offersUsed
std::uint32_t offersUsed() const override
Definition: BookStep.cpp:495
ripple::StrandContext
Context needed to build Strand Steps and for error checking.
Definition: Steps.h:497
ripple::transferRate
Rate transferRate(ReadView const &view, AccountID const &issuer)
Definition: View.cpp:471
@@ -1327,7 +1327,7 @@ $(function() {
ripple::BookOfferCrossingStep::getOfrOutRate
std::uint32_t getOfrOutRate(Step const *prevStep, TOffer< TIn, TOut > const &offer, AccountID const &strandDst, std::uint32_t trOut) const
Definition: BookStep.cpp:424
ripple::BookStep::debtDirection
DebtDirection debtDirection(ReadView const &sb, StrandDirection dir) const override
Definition: BookStep.cpp:119
ripple::BookPaymentStep::limitSelfCrossQuality
bool limitSelfCrossQuality(AccountID const &, AccountID const &, TOffer< TIn, TOut > const &offer, std::optional< Quality > &, FlowOfferStream< TIn, TOut > &, bool) const
Definition: BookStep.cpp:237
-
ripple::getRate
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
Definition: STAmount.cpp:474
+
ripple::getRate
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
Definition: STAmount.cpp:495
ripple::BookStep::ownerPaysTransferFee_
const bool ownerPaysTransferFee_
Definition: BookStep.cpp:51
ripple::BookPaymentStep::adjustQualityWithFees
Quality adjustQualityWithFees(ReadView const &v, Quality const &ofrQ, DebtDirection prevStepDir) const
Definition: BookStep.cpp:275
ripple::Keylet::key
uint256 key
Definition: Keylet.h:40
diff --git a/Book__test_8cpp_source.html b/Book__test_8cpp_source.html index 2eebb5b76f..01f636a826 100644 --- a/Book__test_8cpp_source.html +++ b/Book__test_8cpp_source.html @@ -1822,7 +1822,7 @@ $(function() {
ripple::test::jtx::trust
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition: trust.cpp:30
ripple::SField::fieldName
const std::string fieldName
Definition: SField.h:132
ripple::test::Book_test::testMultipleBooksOneSideEmptyBook
void testMultipleBooksOneSideEmptyBook()
Definition: Book_test.cpp:421
-
ripple::STAmount::getJson
Json::Value getJson(JsonOptions) const override
Definition: STAmount.cpp:634
+
ripple::STAmount::getJson
Json::Value getJson(JsonOptions) const override
Definition: STAmount.cpp:655
std::chrono::milliseconds
ripple::keylet::offer
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition: Indexes.cpp:222
ripple::test::jtx::require
Check a set of conditions.
Definition: require.h:63
diff --git a/Check__test_8cpp_source.html b/Check__test_8cpp_source.html index 49de49b06e..3fd2ced811 100644 --- a/Check__test_8cpp_source.html +++ b/Check__test_8cpp_source.html @@ -2821,7 +2821,7 @@ $(function() {
ripple::Check_test::getCheckIndex
static uint256 getCheckIndex(AccountID const &account, std::uint32_t uSequence)
Definition: Check_test.cpp:91
std::vector
STL class.
ripple::Check_test::testCashIOU
void testCashIOU(FeatureBitset features)
Definition: Check_test.cpp:696
-
ripple::STAmount::getJson
Json::Value getJson(JsonOptions) const override
Definition: STAmount.cpp:634
+
ripple::STAmount::getJson
Json::Value getJson(JsonOptions) const override
Definition: STAmount.cpp:655
ripple::test::jtx::dest_tag::dest_tag
dest_tag(std::uint32_t tag)
Definition: Check_test.cpp:72
ripple::test::jtx::offer_cancel
Json::Value offer_cancel(Account const &account, std::uint32_t offerSeq)
Cancel an offer.
Definition: offer.cpp:45
ripple::tecDST_TAG_NEEDED
@ tecDST_TAG_NEEDED
Definition: TER.h:276
@@ -2866,7 +2866,7 @@ $(function() {
Json::Value::isMember
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:932
std::uint32_t
ripple::sfHighLimit
const SF_AMOUNT sfHighLimit
-
ripple::STAmount::setIssue
void setIssue(Issue const &issue)
Set the Issue for this amount and update mIsNative.
Definition: STAmount.cpp:458
+
ripple::STAmount::setIssue
void setIssue(Issue const &issue)
Set the Issue for this amount and update mIsNative.
Definition: STAmount.cpp:479
ripple::tecPATH_PARTIAL
@ tecPATH_PARTIAL
Definition: TER.h:249
ripple::keylet::line
Keylet line(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition: Indexes.cpp:193
ripple::featureChecks
const uint256 featureChecks
diff --git a/CreateOffer_8cpp_source.html b/CreateOffer_8cpp_source.html index 115e289bde..d6b8325759 100644 --- a/CreateOffer_8cpp_source.html +++ b/CreateOffer_8cpp_source.html @@ -1345,7 +1345,7 @@ $(function() {
ripple::sfTakerPaysCurrency
const SF_UINT160 sfTakerPaysCurrency
ripple::BasicTaker::reject
bool reject(Quality const &quality) const noexcept
Returns true if the quality does not meet the taker's requirements.
Definition: Taker.h:179
ripple::BasicTaker::remaining_offer
Amounts remaining_offer() const
Returns the amount remaining on the offer.
Definition: Taker.cpp:141
-
ripple::STAmount::getText
std::string getText() const override
Definition: STAmount.cpp:550
+
ripple::STAmount::getText
std::string getText() const override
Definition: STAmount.cpp:571
ripple::CrossType::XrpToIou
@ XrpToIou
ripple::STAmount::cMaxNative
static const std::uint64_t cMaxNative
Definition: STAmount.h:68
ripple::ApplyFlags
ApplyFlags
Definition: ApplyView.h:29
@@ -1379,14 +1379,14 @@ $(function() {
ripple::ApplyView
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:134
ripple::lsfHighAuth
@ lsfHighAuth
Definition: LedgerFormats.h:255
ripple::tecKILLED
@ tecKILLED
Definition: TER.h:283
-
ripple::mulRound
STAmount mulRound(STAmount const &v1, STAmount const &v2, Issue const &issue, bool roundUp)
Definition: STAmount.cpp:1284
+
ripple::mulRound
STAmount mulRound(STAmount const &v1, STAmount const &v2, Issue const &issue, bool roundUp)
Definition: STAmount.cpp:1305
ripple::ApplyContext::app
Application & app
Definition: ApplyContext.h:47
ripple::TOffer::quality
const Quality quality() const noexcept
Returns the quality of the offer.
Definition: Offer.h:75
ripple::STAmount::getIssuer
AccountID const & getIssuer() const
Definition: STAmount.h:359
ripple::sfExpiration
const SF_UINT32 sfExpiration
ripple::TOffer::amount
TAmounts< TIn, TOut > const & amount() const
Returns the in and out amounts.
Definition: Offer.h:91
std::tie
T tie(T... args)
-
ripple::getRate
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
Definition: STAmount.cpp:474
+
ripple::getRate
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
Definition: STAmount.cpp:495
ripple::divide
STAmount divide(STAmount const &amount, Rate const &rate)
Definition: Rate2.cpp:86
ripple::sfTakerGetsIssuer
const SF_UINT160 sfTakerGetsIssuer
ripple::base_uint< 160, detail::AccountIDTag >
@@ -1408,7 +1408,7 @@ $(function() {
ripple::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:133
ripple::CreateOffer::preCompute
void preCompute() override
Gather information beyond what the Transactor base class gathers.
Definition: CreateOffer.cpp:886
ripple::offerDelete
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition: View.cpp:893
-
ripple::divRound
STAmount divRound(STAmount const &num, STAmount const &den, Issue const &issue, bool roundUp)
Definition: STAmount.cpp:1370
+
ripple::divRound
STAmount divRound(STAmount const &num, STAmount const &den, Issue const &issue, bool roundUp)
Definition: STAmount.cpp:1391
ripple::TERSubset
Definition: TER.h:340
ripple::TOffer::owner
AccountID const & owner() const
Returns the account id of the offer's owner.
Definition: Offer.h:82
ripple::CreateOffer::step_account
static bool step_account(OfferStream &stream, Taker const &taker)
Definition: CreateOffer.cpp:604
diff --git a/DirectStep_8cpp_source.html b/DirectStep_8cpp_source.html index 1f1c91fe14..28798d3189 100644 --- a/DirectStep_8cpp_source.html +++ b/DirectStep_8cpp_source.html @@ -1076,7 +1076,7 @@ $(function() {
ripple::DirectStepI::Cache
Definition: DirectStep.cpp:49
ripple::rippleCredit
TER rippleCredit(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Definition: View.cpp:933
-
ripple::mulRatio
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
Definition: IOUAmount.cpp:161
+
ripple::mulRatio
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
Definition: IOUAmount.cpp:182
ripple::StrandContext
Context needed to build Strand Steps and for error checking.
Definition: Steps.h:497
ripple::sfHighQualityIn
const SF_UINT32 sfHighQualityIn
ripple::StrandContext::strandSize
const size_t strandSize
Length of Strand.
Definition: Steps.h:509
@@ -1135,7 +1135,7 @@ $(function() {
ripple::DirectStepI::Cache::srcToDst
IOUAmount srcToDst
Definition: DirectStep.cpp:52
ripple::DirectIPaymentStep::logString
std::string logString() const override
Definition: DirectStep.cpp:269
ripple::DirectIPaymentStep::check
TER check(StrandContext const &ctx, std::shared_ptr< const SLE > const &sleSrc) const
Definition: DirectStep.cpp:404
-
ripple::getRate
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
Definition: STAmount.cpp:474
+
ripple::getRate
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
Definition: STAmount.cpp:495
ripple::checkNoRipple
TER checkNoRipple(ReadView const &view, AccountID const &prev, AccountID const &cur, AccountID const &next, Currency const &currency, beast::Journal j)
Definition: StepChecks.h:61
ripple::DirectStepI::setCacheLimiting
void setCacheLimiting(IOUAmount const &fwdIn, IOUAmount const &fwdSrcToDst, IOUAmount const &fwdOut, DebtDirection srcDebtDir)
Definition: DirectStep.cpp:588
ripple::base_uint< 160, detail::AccountIDTag >
diff --git a/Escrow_8cpp_source.html b/Escrow_8cpp_source.html index 3b4e3284df..f891cacf92 100644 --- a/Escrow_8cpp_source.html +++ b/Escrow_8cpp_source.html @@ -680,7 +680,7 @@ $(function() {
ripple::STTx::getSeqProxy
SeqProxy getSeqProxy() const
Definition: STTx.cpp:183
ripple::cryptoconditions
Definition: Condition.h:34
ripple::PreflightContext::j
const beast::Journal j
Definition: Transactor.h:38
-
ripple::STAmount::xrp
XRPAmount xrp() const
Definition: STAmount.cpp:313
+
ripple::STAmount::xrp
XRPAmount xrp() const
Definition: STAmount.cpp:334
ripple::preflight1
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:78
ripple::lsfDepositAuth
@ lsfDepositAuth
Definition: LedgerFormats.h:234
ripple::ApplyContext::app
Application & app
Definition: ApplyContext.h:47
diff --git a/Escrow__test_8cpp_source.html b/Escrow__test_8cpp_source.html index fb86b6891b..eeb9244a5f 100644 --- a/Escrow__test_8cpp_source.html +++ b/Escrow__test_8cpp_source.html @@ -1752,7 +1752,7 @@ $(function() {
std::vector
STL class.
std::find
T find(T... args)
std::array::size
T size(T... args)
-
ripple::STAmount::getJson
Json::Value getJson(JsonOptions) const override
Definition: STAmount.cpp:634
+
ripple::STAmount::getJson
Json::Value getJson(JsonOptions) const override
Definition: STAmount.cpp:655
ripple::test::jtx::Env::jt
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
Definition: Env.h:439
ripple::featureDepositAuth
const uint256 featureDepositAuth
ripple::test::Escrow_test::fb3
const std::array< std::uint8_t, 8 > fb3
Definition: Escrow_test.cpp:55
diff --git a/GatewayBalances__test_8cpp_source.html b/GatewayBalances__test_8cpp_source.html index 0574075596..604d6ec867 100644 --- a/GatewayBalances__test_8cpp_source.html +++ b/GatewayBalances__test_8cpp_source.html @@ -293,7 +293,7 @@ $(function() {
ripple::test::jtx::XRP
const XRP_t XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:105
ripple::test::GatewayBalances_test::run
void run() override
Definition: GatewayBalances_test.cpp:206
ripple::test::jtx::trust
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition: trust.cpp:30
-
ripple::STAmount::getText
std::string getText() const override
Definition: STAmount.cpp:550
+
ripple::STAmount::getText
std::string getText() const override
Definition: STAmount.cpp:571
ripple::test::jtx::Env::app
Application & app()
Definition: Env.h:241
ripple::test::GatewayBalances_test::testGWB
void testGWB(FeatureBitset features)
Definition: GatewayBalances_test.cpp:31
ripple::Application::config
virtual Config & config()=0
diff --git a/IOUAmount_8cpp_source.html b/IOUAmount_8cpp_source.html index 6e3b4ddcd2..3b73f79e22 100644 --- a/IOUAmount_8cpp_source.html +++ b/IOUAmount_8cpp_source.html @@ -98,281 +98,303 @@ $(function() {
27 
28 namespace ripple {
29 
-
30 LocalValue<bool> stNumberSwitchover(true);
+
30 namespace {
31 
-
32 /* The range for the mantissa when normalized */
-
33 static std::int64_t constexpr minMantissa = 1000000000000000ull;
-
34 static std::int64_t constexpr maxMantissa = 9999999999999999ull;
-
35 /* The range for the exponent when normalized */
-
36 static int constexpr minExponent = -96;
-
37 static int constexpr maxExponent = 80;
-
38 
-
39 IOUAmount
-
40 IOUAmount::minPositiveAmount()
-
41 {
-
42  return IOUAmount(minMantissa, minExponent);
-
43 }
-
44 
-
45 void
-
46 IOUAmount::normalize()
-
47 {
-
48  if (mantissa_ == 0)
-
49  {
-
50  *this = beast::zero;
-
51  return;
-
52  }
-
53 
-
54  if (*stNumberSwitchover)
-
55  {
-
56  Number const v{mantissa_, exponent_};
-
57  mantissa_ = v.mantissa();
-
58  exponent_ = v.exponent();
-
59  if (exponent_ > maxExponent)
-
60  Throw<std::overflow_error>("value overflow");
-
61  if (exponent_ < minExponent)
-
62  *this = beast::zero;
-
63  return;
-
64  }
+
32 // Use a static inside a function to help prevent order-of-initialzation issues
+
33 LocalValue<bool>&
+
34 getStaticSTNumberSwitchover()
+
35 {
+
36  static LocalValue<bool> r{true};
+
37  return r;
+
38 }
+
39 } // namespace
+
40 
+
41 bool
+
42 getSTNumberSwitchover()
+
43 {
+
44  return *getStaticSTNumberSwitchover();
+
45 }
+
46 
+
47 void
+
48 setSTNumberSwitchover(bool v)
+
49 {
+
50  *getStaticSTNumberSwitchover() = v;
+
51 }
+
52 
+
53 /* The range for the mantissa when normalized */
+
54 static std::int64_t constexpr minMantissa = 1000000000000000ull;
+
55 static std::int64_t constexpr maxMantissa = 9999999999999999ull;
+
56 /* The range for the exponent when normalized */
+
57 static int constexpr minExponent = -96;
+
58 static int constexpr maxExponent = 80;
+
59 
+
60 IOUAmount
+
61 IOUAmount::minPositiveAmount()
+
62 {
+
63  return IOUAmount(minMantissa, minExponent);
+
64 }
65 
-
66  bool const negative = (mantissa_ < 0);
-
67 
-
68  if (negative)
-
69  mantissa_ = -mantissa_;
-
70 
-
71  while ((mantissa_ < minMantissa) && (exponent_ > minExponent))
-
72  {
-
73  mantissa_ *= 10;
-
74  --exponent_;
-
75  }
-
76 
-
77  while (mantissa_ > maxMantissa)
-
78  {
-
79  if (exponent_ >= maxExponent)
-
80  Throw<std::overflow_error>("IOUAmount::normalize");
-
81 
-
82  mantissa_ /= 10;
-
83  ++exponent_;
-
84  }
-
85 
-
86  if ((exponent_ < minExponent) || (mantissa_ < minMantissa))
-
87  {
-
88  *this = beast::zero;
-
89  return;
-
90  }
+
66 void
+
67 IOUAmount::normalize()
+
68 {
+
69  if (mantissa_ == 0)
+
70  {
+
71  *this = beast::zero;
+
72  return;
+
73  }
+
74 
+
75  if (getSTNumberSwitchover())
+
76  {
+
77  Number const v{mantissa_, exponent_};
+
78  mantissa_ = v.mantissa();
+
79  exponent_ = v.exponent();
+
80  if (exponent_ > maxExponent)
+
81  Throw<std::overflow_error>("value overflow");
+
82  if (exponent_ < minExponent)
+
83  *this = beast::zero;
+
84  return;
+
85  }
+
86 
+
87  bool const negative = (mantissa_ < 0);
+
88 
+
89  if (negative)
+
90  mantissa_ = -mantissa_;
91 
-
92  if (exponent_ > maxExponent)
-
93  Throw<std::overflow_error>("value overflow");
-
94 
-
95  if (negative)
-
96  mantissa_ = -mantissa_;
-
97 }
-
98 
-
99 IOUAmount::IOUAmount(Number const& other)
-
100  : mantissa_(other.mantissa()), exponent_(other.exponent())
-
101 {
-
102  if (exponent_ > maxExponent)
-
103  Throw<std::overflow_error>("value overflow");
-
104  if (exponent_ < minExponent)
-
105  *this = beast::zero;
-
106 }
-
107 
-
108 IOUAmount&
-
109 IOUAmount::operator+=(IOUAmount const& other)
-
110 {
-
111  if (other == beast::zero)
-
112  return *this;
-
113 
-
114  if (*this == beast::zero)
-
115  {
-
116  *this = other;
-
117  return *this;
-
118  }
+
92  while ((mantissa_ < minMantissa) && (exponent_ > minExponent))
+
93  {
+
94  mantissa_ *= 10;
+
95  --exponent_;
+
96  }
+
97 
+
98  while (mantissa_ > maxMantissa)
+
99  {
+
100  if (exponent_ >= maxExponent)
+
101  Throw<std::overflow_error>("IOUAmount::normalize");
+
102 
+
103  mantissa_ /= 10;
+
104  ++exponent_;
+
105  }
+
106 
+
107  if ((exponent_ < minExponent) || (mantissa_ < minMantissa))
+
108  {
+
109  *this = beast::zero;
+
110  return;
+
111  }
+
112 
+
113  if (exponent_ > maxExponent)
+
114  Throw<std::overflow_error>("value overflow");
+
115 
+
116  if (negative)
+
117  mantissa_ = -mantissa_;
+
118 }
119 
-
120  if (*stNumberSwitchover)
-
121  {
-
122  *this = IOUAmount{Number{*this} + Number{other}};
-
123  return *this;
-
124  }
-
125  auto m = other.mantissa_;
-
126  auto e = other.exponent_;
-
127 
-
128  while (exponent_ < e)
-
129  {
-
130  mantissa_ /= 10;
-
131  ++exponent_;
-
132  }
-
133 
-
134  while (e < exponent_)
-
135  {
-
136  m /= 10;
-
137  ++e;
-
138  }
-
139 
-
140  // This addition cannot overflow an std::int64_t but we may throw from
-
141  // normalize if the result isn't representable.
-
142  mantissa_ += m;
-
143 
-
144  if (mantissa_ >= -10 && mantissa_ <= 10)
-
145  {
-
146  *this = beast::zero;
-
147  return *this;
-
148  }
-
149 
-
150  normalize();
-
151  return *this;
-
152 }
-
153 
-
154 std::string
-
155 to_string(IOUAmount const& amount)
-
156 {
-
157  return to_string(Number{amount});
-
158 }
-
159 
-
160 IOUAmount
-
161 mulRatio(
-
162  IOUAmount const& amt,
-
163  std::uint32_t num,
-
164  std::uint32_t den,
-
165  bool roundUp)
-
166 {
-
167  using namespace boost::multiprecision;
-
168 
-
169  if (!den)
-
170  Throw<std::runtime_error>("division by zero");
-
171 
-
172  // A vector with the value 10^index for indexes from 0 to 29
-
173  // The largest intermediate value we expect is 2^96, which
-
174  // is less than 10^29
-
175  static auto const powerTable = [] {
-
176  std::vector<uint128_t> result;
-
177  result.reserve(30); // 2^96 is largest intermediate result size
-
178  uint128_t cur(1);
-
179  for (int i = 0; i < 30; ++i)
-
180  {
-
181  result.push_back(cur);
-
182  cur *= 10;
-
183  };
-
184  return result;
-
185  }();
-
186 
-
187  // Return floor(log10(v))
-
188  // Note: Returns -1 for v == 0
-
189  static auto log10Floor = [](uint128_t const& v) {
-
190  // Find the index of the first element >= the requested element, the
-
191  // index is the log of the element in the log table.
-
192  auto const l =
-
193  std::lower_bound(powerTable.begin(), powerTable.end(), v);
-
194  int index = std::distance(powerTable.begin(), l);
-
195  // If we're not equal, subtract to get the floor
-
196  if (*l != v)
-
197  --index;
-
198  return index;
-
199  };
-
200 
-
201  // Return ceil(log10(v))
-
202  static auto log10Ceil = [](uint128_t const& v) {
-
203  // Find the index of the first element >= the requested element, the
-
204  // index is the log of the element in the log table.
-
205  auto const l =
-
206  std::lower_bound(powerTable.begin(), powerTable.end(), v);
-
207  return int(std::distance(powerTable.begin(), l));
-
208  };
-
209 
-
210  static auto const fl64 =
-
211  log10Floor(std::numeric_limits<std::int64_t>::max());
-
212 
-
213  bool const neg = amt.mantissa() < 0;
-
214  uint128_t const den128(den);
-
215  // a 32 value * a 64 bit value and stored in a 128 bit value. This will
-
216  // never overflow
-
217  uint128_t const mul =
-
218  uint128_t(neg ? -amt.mantissa() : amt.mantissa()) * uint128_t(num);
-
219 
-
220  auto low = mul / den128;
-
221  uint128_t rem(mul - low * den128);
-
222 
-
223  int exponent = amt.exponent();
-
224 
-
225  if (rem)
-
226  {
-
227  // Mathematically, the result is low + rem/den128. However, since this
-
228  // uses integer division rem/den128 will be zero. Scale the result so
-
229  // low does not overflow the largest amount we can store in the mantissa
-
230  // and (rem/den128) is as large as possible. Scale by multiplying low
-
231  // and rem by 10 and subtracting one from the exponent. We could do this
-
232  // with a loop, but it's more efficient to use logarithms.
-
233  auto const roomToGrow = fl64 - log10Ceil(low);
-
234  if (roomToGrow > 0)
-
235  {
-
236  exponent -= roomToGrow;
-
237  low *= powerTable[roomToGrow];
-
238  rem *= powerTable[roomToGrow];
-
239  }
-
240  auto const addRem = rem / den128;
-
241  low += addRem;
-
242  rem = rem - addRem * den128;
-
243  }
-
244 
-
245  // The largest result we can have is ~2^95, which overflows the 64 bit
-
246  // result we can store in the mantissa. Scale result down by dividing by ten
-
247  // and adding one to the exponent until the low will fit in the 64-bit
-
248  // mantissa. Use logarithms to avoid looping.
-
249  bool hasRem = bool(rem);
-
250  auto const mustShrink = log10Ceil(low) - fl64;
-
251  if (mustShrink > 0)
-
252  {
-
253  uint128_t const sav(low);
-
254  exponent += mustShrink;
-
255  low /= powerTable[mustShrink];
-
256  if (!hasRem)
-
257  hasRem = bool(sav - low * powerTable[mustShrink]);
-
258  }
-
259 
-
260  std::int64_t mantissa = low.convert_to<std::int64_t>();
-
261 
-
262  // normalize before rounding
-
263  if (neg)
-
264  mantissa *= -1;
+
120 IOUAmount::IOUAmount(Number const& other)
+
121  : mantissa_(other.mantissa()), exponent_(other.exponent())
+
122 {
+
123  if (exponent_ > maxExponent)
+
124  Throw<std::overflow_error>("value overflow");
+
125  if (exponent_ < minExponent)
+
126  *this = beast::zero;
+
127 }
+
128 
+
129 IOUAmount&
+
130 IOUAmount::operator+=(IOUAmount const& other)
+
131 {
+
132  if (other == beast::zero)
+
133  return *this;
+
134 
+
135  if (*this == beast::zero)
+
136  {
+
137  *this = other;
+
138  return *this;
+
139  }
+
140 
+
141  if (getSTNumberSwitchover())
+
142  {
+
143  *this = IOUAmount{Number{*this} + Number{other}};
+
144  return *this;
+
145  }
+
146  auto m = other.mantissa_;
+
147  auto e = other.exponent_;
+
148 
+
149  while (exponent_ < e)
+
150  {
+
151  mantissa_ /= 10;
+
152  ++exponent_;
+
153  }
+
154 
+
155  while (e < exponent_)
+
156  {
+
157  m /= 10;
+
158  ++e;
+
159  }
+
160 
+
161  // This addition cannot overflow an std::int64_t but we may throw from
+
162  // normalize if the result isn't representable.
+
163  mantissa_ += m;
+
164 
+
165  if (mantissa_ >= -10 && mantissa_ <= 10)
+
166  {
+
167  *this = beast::zero;
+
168  return *this;
+
169  }
+
170 
+
171  normalize();
+
172  return *this;
+
173 }
+
174 
+
175 std::string
+
176 to_string(IOUAmount const& amount)
+
177 {
+
178  return to_string(Number{amount});
+
179 }
+
180 
+
181 IOUAmount
+
182 mulRatio(
+
183  IOUAmount const& amt,
+
184  std::uint32_t num,
+
185  std::uint32_t den,
+
186  bool roundUp)
+
187 {
+
188  using namespace boost::multiprecision;
+
189 
+
190  if (!den)
+
191  Throw<std::runtime_error>("division by zero");
+
192 
+
193  // A vector with the value 10^index for indexes from 0 to 29
+
194  // The largest intermediate value we expect is 2^96, which
+
195  // is less than 10^29
+
196  static auto const powerTable = [] {
+
197  std::vector<uint128_t> result;
+
198  result.reserve(30); // 2^96 is largest intermediate result size
+
199  uint128_t cur(1);
+
200  for (int i = 0; i < 30; ++i)
+
201  {
+
202  result.push_back(cur);
+
203  cur *= 10;
+
204  };
+
205  return result;
+
206  }();
+
207 
+
208  // Return floor(log10(v))
+
209  // Note: Returns -1 for v == 0
+
210  static auto log10Floor = [](uint128_t const& v) {
+
211  // Find the index of the first element >= the requested element, the
+
212  // index is the log of the element in the log table.
+
213  auto const l =
+
214  std::lower_bound(powerTable.begin(), powerTable.end(), v);
+
215  int index = std::distance(powerTable.begin(), l);
+
216  // If we're not equal, subtract to get the floor
+
217  if (*l != v)
+
218  --index;
+
219  return index;
+
220  };
+
221 
+
222  // Return ceil(log10(v))
+
223  static auto log10Ceil = [](uint128_t const& v) {
+
224  // Find the index of the first element >= the requested element, the
+
225  // index is the log of the element in the log table.
+
226  auto const l =
+
227  std::lower_bound(powerTable.begin(), powerTable.end(), v);
+
228  return int(std::distance(powerTable.begin(), l));
+
229  };
+
230 
+
231  static auto const fl64 =
+
232  log10Floor(std::numeric_limits<std::int64_t>::max());
+
233 
+
234  bool const neg = amt.mantissa() < 0;
+
235  uint128_t const den128(den);
+
236  // a 32 value * a 64 bit value and stored in a 128 bit value. This will
+
237  // never overflow
+
238  uint128_t const mul =
+
239  uint128_t(neg ? -amt.mantissa() : amt.mantissa()) * uint128_t(num);
+
240 
+
241  auto low = mul / den128;
+
242  uint128_t rem(mul - low * den128);
+
243 
+
244  int exponent = amt.exponent();
+
245 
+
246  if (rem)
+
247  {
+
248  // Mathematically, the result is low + rem/den128. However, since this
+
249  // uses integer division rem/den128 will be zero. Scale the result so
+
250  // low does not overflow the largest amount we can store in the mantissa
+
251  // and (rem/den128) is as large as possible. Scale by multiplying low
+
252  // and rem by 10 and subtracting one from the exponent. We could do this
+
253  // with a loop, but it's more efficient to use logarithms.
+
254  auto const roomToGrow = fl64 - log10Ceil(low);
+
255  if (roomToGrow > 0)
+
256  {
+
257  exponent -= roomToGrow;
+
258  low *= powerTable[roomToGrow];
+
259  rem *= powerTable[roomToGrow];
+
260  }
+
261  auto const addRem = rem / den128;
+
262  low += addRem;
+
263  rem = rem - addRem * den128;
+
264  }
265 
-
266  IOUAmount result(mantissa, exponent);
-
267 
-
268  if (hasRem)
-
269  {
-
270  // handle rounding
-
271  if (roundUp && !neg)
-
272  {
-
273  if (!result)
-
274  {
-
275  return IOUAmount::minPositiveAmount();
-
276  }
-
277  // This addition cannot overflow because the mantissa is already
-
278  // normalized
-
279  return IOUAmount(result.mantissa() + 1, result.exponent());
-
280  }
-
281 
-
282  if (!roundUp && neg)
-
283  {
-
284  if (!result)
-
285  {
-
286  return IOUAmount(-minMantissa, minExponent);
-
287  }
-
288  // This subtraction cannot underflow because `result` is not zero
-
289  return IOUAmount(result.mantissa() - 1, result.exponent());
-
290  }
-
291  }
-
292 
-
293  return result;
-
294 }
-
295 
-
296 } // namespace ripple
+
266  // The largest result we can have is ~2^95, which overflows the 64 bit
+
267  // result we can store in the mantissa. Scale result down by dividing by ten
+
268  // and adding one to the exponent until the low will fit in the 64-bit
+
269  // mantissa. Use logarithms to avoid looping.
+
270  bool hasRem = bool(rem);
+
271  auto const mustShrink = log10Ceil(low) - fl64;
+
272  if (mustShrink > 0)
+
273  {
+
274  uint128_t const sav(low);
+
275  exponent += mustShrink;
+
276  low /= powerTable[mustShrink];
+
277  if (!hasRem)
+
278  hasRem = bool(sav - low * powerTable[mustShrink]);
+
279  }
+
280 
+
281  std::int64_t mantissa = low.convert_to<std::int64_t>();
+
282 
+
283  // normalize before rounding
+
284  if (neg)
+
285  mantissa *= -1;
+
286 
+
287  IOUAmount result(mantissa, exponent);
+
288 
+
289  if (hasRem)
+
290  {
+
291  // handle rounding
+
292  if (roundUp && !neg)
+
293  {
+
294  if (!result)
+
295  {
+
296  return IOUAmount::minPositiveAmount();
+
297  }
+
298  // This addition cannot overflow because the mantissa is already
+
299  // normalized
+
300  return IOUAmount(result.mantissa() + 1, result.exponent());
+
301  }
+
302 
+
303  if (!roundUp && neg)
+
304  {
+
305  if (!result)
+
306  {
+
307  return IOUAmount(-minMantissa, minExponent);
+
308  }
+
309  // This subtraction cannot underflow because `result` is not zero
+
310  return IOUAmount(result.mantissa() - 1, result.exponent());
+
311  }
+
312  }
+
313 
+
314  return result;
+
315 }
+
316 
+
317 } // namespace ripple
-
ripple::mulRatio
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
Definition: IOUAmount.cpp:161
+
ripple::mulRatio
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
Definition: IOUAmount.cpp:182
ripple::IOUAmount::exponent
int exponent() const noexcept
Definition: IOUAmount.h:163
-
ripple::maxExponent
static constexpr int maxExponent
Definition: IOUAmount.cpp:37
+
ripple::maxExponent
static constexpr int maxExponent
Definition: IOUAmount.cpp:58
+
ripple::setSTNumberSwitchover
void setSTNumberSwitchover(bool v)
Definition: IOUAmount.cpp:48
std::string
STL class.
-
ripple::IOUAmount::minPositiveAmount
static IOUAmount minPositiveAmount()
Definition: IOUAmount.cpp:40
+
ripple::IOUAmount::minPositiveAmount
static IOUAmount minPositiveAmount()
Definition: IOUAmount.cpp:61
std::vector::reserve
T reserve(T... args)
-
ripple::IOUAmount::normalize
void normalize()
Adjusts the mantissa and exponent to the proper range.
Definition: IOUAmount.cpp:46
+
ripple::IOUAmount::normalize
void normalize()
Adjusts the mantissa and exponent to the proper range.
Definition: IOUAmount.cpp:67
std::vector
STL class.
iterator
std::distance
T distance(T... args)
@@ -383,19 +405,19 @@ $(function() {
ripple::Number
Definition: Number.h:36
ripple::IOUAmount::mantissa_
std::int64_t mantissa_
Definition: IOUAmount.h:47
ripple::IOUAmount::exponent_
int exponent_
Definition: IOUAmount.h:48
-
ripple::maxMantissa
static constexpr std::int64_t maxMantissa
Definition: IOUAmount.cpp:34
-
ripple::minExponent
static constexpr int minExponent
Definition: IOUAmount.cpp:36
+
ripple::maxMantissa
static constexpr std::int64_t maxMantissa
Definition: IOUAmount.cpp:55
+
ripple::minExponent
static constexpr int minExponent
Definition: IOUAmount.cpp:57
ripple::IOUAmount::IOUAmount
IOUAmount()=default
std::int64_t
-
ripple::IOUAmount::operator+=
IOUAmount & operator+=(IOUAmount const &other)
Definition: IOUAmount.cpp:109
+
ripple::IOUAmount::operator+=
IOUAmount & operator+=(IOUAmount const &other)
Definition: IOUAmount.cpp:130
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::IOUAmount::mantissa
std::int64_t mantissa() const noexcept
Definition: IOUAmount.h:169
std::lower_bound
T lower_bound(T... args)
+
ripple::getSTNumberSwitchover
bool getSTNumberSwitchover()
Definition: IOUAmount.cpp:42
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:41
numeric
-
ripple::stNumberSwitchover
LocalValue< bool > stNumberSwitchover(true)
Definition: IOUAmount.h:189
std::numeric_limits
-
ripple::minMantissa
static constexpr std::int64_t minMantissa
Definition: IOUAmount.cpp:33
+
ripple::minMantissa
static constexpr std::int64_t minMantissa
Definition: IOUAmount.cpp:54