Struct XrplNumber
A value of the XRPL Number type, used by the Single Asset Vault (XLS-65) and
Lending Protocol (XLS-66) fields such as AssetsTotal, PrincipalOutstanding or
PeriodicPayment.
Assembly: Xrpl.BinaryCodec.dll
Syntax
[JsonConverter(typeof(XrplNumberJsonConverter))]
public readonly struct XrplNumber
Constructors
|
Edit this page
View Source
XrplNumber(long, int)
Creates a value from the wire form: mantissa × 10^exponent.
The pair does not have to be normalized. As in rippled, a value too small for the exponent
range becomes zero.
Declaration
public XrplNumber(long mantissa, int exponent)
Parameters
| Type |
Name |
Description |
| long |
mantissa |
|
| int |
exponent |
|
Exceptions
| Type |
Condition |
| OverflowException |
The value is too large for the exponent range, or mantissa is
long.MinValue, which rippled cannot hold without rounding.
|
Fields
|
Edit this page
View Source
MaxExponent
Largest exponent of a normalized value.
Declaration
public const int MaxExponent = 32768
Field Value
|
Edit this page
View Source
MinExponent
Smallest exponent of a normalized value.
Declaration
public const int MinExponent = -32768
Field Value
|
Edit this page
View Source
Zero
Declaration
public static readonly XrplNumber Zero
Field Value
Properties
|
Edit this page
View Source
Exponent
Exponent of the wire form, int.MinValue for zero.
Matches rippled's Number::exponent().
Declaration
public int Exponent { get; }
Property Value
|
Edit this page
View Source
IsNegative
Whether the value is below zero.
Declaration
public bool IsNegative { get; }
Property Value
|
Edit this page
View Source
IsZero
Whether the value is zero.
Declaration
public bool IsZero { get; }
Property Value
|
Edit this page
View Source
Mantissa
Mantissa of the wire form: signed, at most 9223372036854775807 in absolute value, 0 for zero.
Matches rippled's Number::mantissa().
Declaration
public long Mantissa { get; }
Property Value
|
Edit this page
View Source
Sign
-1, 0 or 1 by the sign of the value.
Declaration
Property Value
Methods
|
Edit this page
View Source
Abs(XrplNumber)
Declaration
public static XrplNumber Abs(XrplNumber x)
Parameters
Returns
|
Edit this page
View Source
Add(XrplNumber, XrplNumber, NumberContext)
x + y, rounded under context.
Declaration
public static XrplNumber Add(XrplNumber x, XrplNumber y, NumberContext context)
Parameters
Returns
Exceptions
| Type |
Condition |
| OverflowException |
The result is beyond the exponent range.
|
|
Edit this page
View Source
CompareTo(object)
Declaration
public int CompareTo(object obj)
Parameters
| Type |
Name |
Description |
| object |
obj |
|
Returns
|
Edit this page
View Source
CompareTo(XrplNumber)
Declaration
public int CompareTo(XrplNumber other)
Parameters
Returns
|
Edit this page
View Source
Divide(XrplNumber, XrplNumber, NumberContext)
x / y, rounded under context.
Declaration
public static XrplNumber Divide(XrplNumber x, XrplNumber y, NumberContext context)
Parameters
Returns
Exceptions
| Type |
Condition |
| DivideByZeroException |
y is zero.
|
| OverflowException |
The result is beyond the exponent range.
|
|
Edit this page
View Source
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
| Type |
Name |
Description |
| object |
obj |
|
Returns
Overrides
System.ValueType.Equals(object)
|
Edit this page
View Source
Equals(XrplNumber)
Declaration
public bool Equals(XrplNumber other)
Parameters
Returns
|
Edit this page
View Source
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Overrides
System.ValueType.GetHashCode()
|
Edit this page
View Source
Multiply(XrplNumber, XrplNumber, NumberContext)
x * y, rounded under context.
Declaration
public static XrplNumber Multiply(XrplNumber x, XrplNumber y, NumberContext context)
Parameters
Returns
Exceptions
| Type |
Condition |
| OverflowException |
The result is beyond the exponent range.
|
|
Edit this page
View Source
Parse(string)
Parses a decimal or scientific number: "1000", "-0.025", "1e13".
Declaration
public static XrplNumber Parse(string text)
Parameters
| Type |
Name |
Description |
| string |
text |
|
Returns
Exceptions
| Type |
Condition |
| FormatException |
The text is not a number, has more significant digits than the ledger holds exactly, or is
out of the exponent range.
|
|
Edit this page
View Source
Power(XrplNumber, uint, NumberContext)
x^n by repeated squaring, rounded at each step as rippled's power.
Declaration
public static XrplNumber Power(XrplNumber x, uint n, NumberContext context)
Parameters
Returns
Exceptions
| Type |
Condition |
| OverflowException |
The result is beyond the exponent range.
|
|
Edit this page
View Source
Root2(XrplNumber, NumberContext)
The square root of x, as rippled's root2.
Declaration
public static XrplNumber Root2(XrplNumber x, NumberContext context)
Parameters
Returns
Exceptions
| Type |
Condition |
| OverflowException |
x is negative.
|
| ArithmeticException |
The root does not converge: rippled's Newton-Raphson loop would cycle forever on this input.
|
|
Edit this page
View Source
Subtract(XrplNumber, XrplNumber, NumberContext)
x - y, rounded under context.
Declaration
public static XrplNumber Subtract(XrplNumber x, XrplNumber y, NumberContext context)
Parameters
Returns
Exceptions
| Type |
Condition |
| OverflowException |
The result is beyond the exponent range.
|
|
Edit this page
View Source
ToInt64(NumberContext)
The value as an integer, rounded in the context's mode, as rippled's conversion to
std::int64_t.
Declaration
public long ToInt64(NumberContext context)
Parameters
Returns
Exceptions
| Type |
Condition |
| OverflowException |
The value is beyond long.
|
|
Edit this page
View Source
ToString()
The value as rippled writes it in JSON (to_string(Number)).
Declaration
public override string ToString()
Returns
Overrides
System.ValueType.ToString()
|
Edit this page
View Source
Truncate(NumberContext)
The value with its fraction dropped, as rippled's truncate.
Declaration
public XrplNumber Truncate(NumberContext context)
Parameters
Returns
|
Edit this page
View Source
TryParse(string, out XrplNumber)
Parses a number the way Parse(string) does, returning false instead of
throwing.
Declaration
public static bool TryParse(string text, out XrplNumber value)
Parameters
| Type |
Name |
Description |
| string |
text |
|
| XrplNumber |
value |
|
Returns
|
Edit this page
View Source
TryToDecimal(out decimal)
Converts to decimal. A value with more fractional digits than
decimal holds (28) is rounded to nearest, ties to even; a value too small for
that scale becomes zero.
Declaration
public bool TryToDecimal(out decimal value)
Parameters
| Type |
Name |
Description |
| decimal |
value |
|
Returns
| Type |
Description |
| bool |
false when the value is beyond the range of decimal.
|
Operators
|
Edit this page
View Source
operator +(XrplNumber, XrplNumber)
Declaration
public static XrplNumber operator +(XrplNumber x, XrplNumber y)
Parameters
Returns
|
Edit this page
View Source
operator /(XrplNumber, XrplNumber)
Declaration
public static XrplNumber operator /(XrplNumber x, XrplNumber y)
Parameters
Returns
|
Edit this page
View Source
operator ==(XrplNumber, XrplNumber)
Declaration
public static bool operator ==(XrplNumber left, XrplNumber right)
Parameters
Returns
|
Edit this page
View Source
explicit operator XrplNumber(decimal)
Declaration
public static explicit operator XrplNumber(decimal value)
Parameters
| Type |
Name |
Description |
| decimal |
value |
|
Returns
Exceptions
| Type |
Condition |
| OverflowException |
The value has more significant digits than the ledger holds exactly; round it first.
|
|
Edit this page
View Source
explicit operator XrplNumber(long)
Declaration
public static explicit operator XrplNumber(long value)
Parameters
| Type |
Name |
Description |
| long |
value |
|
Returns
Exceptions
| Type |
Condition |
| OverflowException |
The value is long.MinValue.
|
|
Edit this page
View Source
explicit operator decimal(XrplNumber)
Declaration
public static explicit operator decimal(XrplNumber number)
Parameters
Returns
Exceptions
| Type |
Condition |
| OverflowException |
The value is beyond the range of decimal.
|
|
Edit this page
View Source
operator >(XrplNumber, XrplNumber)
Declaration
public static bool operator >(XrplNumber left, XrplNumber right)
Parameters
Returns
|
Edit this page
View Source
operator >=(XrplNumber, XrplNumber)
Declaration
public static bool operator >=(XrplNumber left, XrplNumber right)
Parameters
Returns
|
Edit this page
View Source
implicit operator XrplNumber(int)
Converts from int; always exact.
Declaration
public static implicit operator XrplNumber(int value)
Parameters
| Type |
Name |
Description |
| int |
value |
|
Returns
|
Edit this page
View Source
operator !=(XrplNumber, XrplNumber)
Declaration
public static bool operator !=(XrplNumber left, XrplNumber right)
Parameters
Returns
|
Edit this page
View Source
operator <(XrplNumber, XrplNumber)
Declaration
public static bool operator <(XrplNumber left, XrplNumber right)
Parameters
Returns
|
Edit this page
View Source
operator <=(XrplNumber, XrplNumber)
Declaration
public static bool operator <=(XrplNumber left, XrplNumber right)
Parameters
Returns
|
Edit this page
View Source
operator *(XrplNumber, XrplNumber)
Declaration
public static XrplNumber operator *(XrplNumber x, XrplNumber y)
Parameters
Returns
|
Edit this page
View Source
operator -(XrplNumber, XrplNumber)
Declaration
public static XrplNumber operator -(XrplNumber x, XrplNumber y)
Parameters
Returns
|
Edit this page
View Source
operator -(XrplNumber)
Negation, which is always exact.
Declaration
public static XrplNumber operator -(XrplNumber x)
Parameters
Returns