pub struct Number(/* private fields */);Expand description
An opaque XRPL STNumber value: a decimal float represented as mantissa × 10^exponent.
The wire format is 12 bytes — an 8-byte big-endian i64 mantissa followed by a 4-byte
big-endian i32 exponent. This is the representation every float_* host function consumes
and produces, and it is distinct from the 8-byte
IOUNumber value carried inside an IOU STAmount.
§Important
This type is intentionally opaque: arithmetic and conversions MUST go through the host, which
delegates to rippled’s Number class so results stay exactly consensus-compatible. The bytes
are only ever produced by the host, so callers cannot construct an out-of-range value.
PartialEq/Eq compare the raw bytes. The host canonicalizes every value it emits, so bytewise
equality matches semantic equality for host-produced values.
Implementations§
Source§impl Number
impl Number
Sourcepub const NEGATIVE_ONE: Number
pub const NEGATIVE_ONE: Number
The value -1 (mantissa = -1,000,000,000,000,000,000, exponent = -18).
Sourcepub fn from_mant_exp(mantissa: i64, exponent: i32) -> Result<Number>
pub fn from_mant_exp(mantissa: i64, exponent: i32) -> Result<Number>
Constructs a Number from an explicit mantissa and exponent (mantissa × 10^exponent).
Sourcepub fn from_stamount(bytes: &[u8]) -> Result<Number>
pub fn from_stamount(bytes: &[u8]) -> Result<Number>
Converts a serialized STAmount (e.g. from an amount field) to a Number.
Sourcepub fn from_stnumber(bytes: &[u8]) -> Result<Number>
pub fn from_stnumber(bytes: &[u8]) -> Result<Number>
Converts a serialized STNumber (12-byte) to a Number.
Sourcepub fn to_int(&self) -> Result<i64>
pub fn to_int(&self) -> Result<i64>
Converts this Number to a signed integer, rounding to nearest.
Sourcepub fn to_mant_exp(&self) -> Result<(i64, i32)>
pub fn to_mant_exp(&self) -> Result<(i64, i32)>
Decomposes this Number into its (mantissa, exponent) components.
No rounding is applied — the value is already rounded/canonical.
Sourcepub fn add(&self, other: &Number, rounding: RoundingMode) -> Result<Number>
pub fn add(&self, other: &Number, rounding: RoundingMode) -> Result<Number>
Returns self + other, rounding per rounding.
Sourcepub fn subtract(&self, other: &Number, rounding: RoundingMode) -> Result<Number>
pub fn subtract(&self, other: &Number, rounding: RoundingMode) -> Result<Number>
Returns self - other, rounding per rounding.
Sourcepub fn multiply(&self, other: &Number, rounding: RoundingMode) -> Result<Number>
pub fn multiply(&self, other: &Number, rounding: RoundingMode) -> Result<Number>
Returns self * other, rounding per rounding.
Trait Implementations§
impl Eq for Number
Source§impl FieldDecoder for Number
FieldDecoder for XRPL STNumber fields: decodes the 12-byte serialized value, failing if the
host wrote a different number of bytes.
impl FieldDecoder for Number
FieldDecoder for XRPL STNumber fields: decodes the 12-byte serialized value, failing if the
host wrote a different number of bytes.
The bytes are taken as-is rather than routed back through float_from_stnumber: the host’s float
representation is the STNumber serialization (rippled’s WASM host builds it with
STNumber::add), so a value read off a transaction or ledger entry is already a canonical
host-produced Number.