Show / Hide Table of Contents

Class XrplAmountMath

rippled's STAmount arithmetic on XrplAmount, bit for bit: addition, multiply, divide, and the directed rounding mulRound / divRound that offer crossing uses, in both their legacy and strict forms.

Inheritance
object
XrplAmountMath
Namespace: Xrpl.Amounts
Assembly: Xrpl.dll
Syntax
public static class XrplAmountMath
Remarks

LedgerRules supplies what the node switches on: the Number scale, and MPTokensV2 and fixCleanup3_5_0, under which a rounded product or quotient with an MPT operand goes through Number arithmetic. null means the current rules.

The strict forms differ from the legacy ones in two places only. An integral result (XRP, MPT) keeps every discarded digit when it decides to round up. And the final amount is built under a fixed rounding mode - toward zero for a product, away from or toward zero as asked for a quotient - where the legacy forms use the ambient mode, rounding to nearest. So a legacy MulRound(XrplAmount, XrplAmount, IssuedCurrency, bool, LedgerRules) asked to round down may round an issued currency to nearest.

Methods

| Edit this page View Source

Add(XrplAmount, XrplAmount, LedgerRules)

STAmount + STAmount.

Declaration
public static XrplAmount Add(XrplAmount a, XrplAmount b, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount a
XrplAmount b
LedgerRules rules
Returns
Type Description
XrplAmount
Exceptions
Type Condition
ArgumentException

The amounts are of different assets.

OverflowException

The sum is beyond what the asset can hold.

| Edit this page View Source

DivRound(XrplAmount, XrplAmount, IssuedCurrency, bool, LedgerRules)

divRound: the quotient as an amount of asset, away from zero when roundUp, otherwise toward zero - with the legacy rounding described on the class.

Declaration
public static XrplAmount DivRound(XrplAmount num, XrplAmount den, Common.IssuedCurrency asset, bool roundUp, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount num
XrplAmount den
Common.IssuedCurrency asset
bool roundUp
LedgerRules rules
Returns
Type Description
XrplAmount
Exceptions
Type Condition
DivideByZeroException

den is zero.

| Edit this page View Source

DivRoundStrict(XrplAmount, XrplAmount, IssuedCurrency, bool, LedgerRules)

divRoundStrict: DivRound(XrplAmount, XrplAmount, IssuedCurrency, bool, LedgerRules) built in the requested direction.

Declaration
public static XrplAmount DivRoundStrict(XrplAmount num, XrplAmount den, Common.IssuedCurrency asset, bool roundUp, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount num
XrplAmount den
Common.IssuedCurrency asset
bool roundUp
LedgerRules rules
Returns
Type Description
XrplAmount
Exceptions
Type Condition
DivideByZeroException

den is zero.

| Edit this page View Source

Divide(XrplAmount, XrplAmount, IssuedCurrency, LedgerRules)

divide(num, den, asset): both mantissas scaled to at least 10^15, num * 10^17 / den truncated, plus 5, as an amount of asset.

Declaration
public static XrplAmount Divide(XrplAmount num, XrplAmount den, Common.IssuedCurrency asset, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount num
XrplAmount den
Common.IssuedCurrency asset
LedgerRules rules
Returns
Type Description
XrplAmount
Exceptions
Type Condition
DivideByZeroException

den is zero.

OverflowException

The quotient is beyond what the asset can hold.

| Edit this page View Source

MulRound(XrplAmount, XrplAmount, IssuedCurrency, bool, LedgerRules)

mulRound: the product as an amount of asset, away from zero when roundUp, otherwise toward zero - with the legacy rounding described on the class.

Declaration
public static XrplAmount MulRound(XrplAmount v1, XrplAmount v2, Common.IssuedCurrency asset, bool roundUp, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount v1
XrplAmount v2
Common.IssuedCurrency asset
bool roundUp
LedgerRules rules
Returns
Type Description
XrplAmount
| Edit this page View Source

MulRoundStrict(XrplAmount, XrplAmount, IssuedCurrency, bool, LedgerRules)

mulRoundStrict: MulRound(XrplAmount, XrplAmount, IssuedCurrency, bool, LedgerRules) with every discarded digit counted.

Declaration
public static XrplAmount MulRoundStrict(XrplAmount v1, XrplAmount v2, Common.IssuedCurrency asset, bool roundUp, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount v1
XrplAmount v2
Common.IssuedCurrency asset
bool roundUp
LedgerRules rules
Returns
Type Description
XrplAmount
| Edit this page View Source

Multiply(XrplAmount, XrplAmount, IssuedCurrency, LedgerRules)

multiply(v1, v2, asset): the product as an amount of asset, exact for XRP x XRP and MPT x MPT, otherwise through Number.

Declaration
public static XrplAmount Multiply(XrplAmount v1, XrplAmount v2, Common.IssuedCurrency asset, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount v1
XrplAmount v2
Common.IssuedCurrency asset
LedgerRules rules
Returns
Type Description
XrplAmount
Exceptions
Type Condition
OverflowException

The product is beyond what the asset can hold.

| Edit this page View Source

Multiply(XrplAmount, XrplNumber, NumberRounding, LedgerRules)

multiply(amount, frac, rm): the product computed in rounding, then made an amount of the asset in the same mode (toSTAmount).

Declaration
public static XrplAmount Multiply(XrplAmount amount, XrplNumber fraction, NumberRounding rounding, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount amount
XrplNumber fraction
NumberRounding rounding
LedgerRules rules
Returns
Type Description
XrplAmount
| Edit this page View Source

Subtract(XrplAmount, XrplAmount, LedgerRules)

STAmount - STAmount.

Declaration
public static XrplAmount Subtract(XrplAmount a, XrplAmount b, LedgerRules rules = null)
Parameters
Type Name Description
XrplAmount a
XrplAmount b
LedgerRules rules
Returns
Type Description
XrplAmount
Exceptions
Type Condition
ArgumentException

The amounts are of different assets.

OverflowException

The difference is beyond what the asset can hold.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX