Modules decimal128.move and decimal256.move
These modules implement functions that can be used to work with fixed precision (18 decimal digits) unsigned numbers that can be represented in, respectively, 128 and 256 bits.
The modules expose functions to create a Decimal128/Decimal256 number from a raw value (already premultiplied by 1e18) as well as parsing a number from a string. Note that an issue with number parsing is discussed in issue ref↗.
These functions are implemented in decimal128:
new: Creates aDecimal128from a (premultiplied)u128value.new_u64: Creates aDecimal128from a (premultiplied)u64value.one: Creates aDecimal128with value 1.zero: Creates aDecimal128with zero value.from_ratio_u64: Creates aDecimal128that represents the ratio between twou64integers.from_ratio: Creates aDecimal128that represents the ratio between twou128integers.add: Adds twoDecimal128, returning a newDecimal128as a result.sub: Adds twoDecimal128, returning a newDecimal128as a result.mul_u64: Multiplies aDecimal128by au64integer value, returning an unscaledu64integer result.mul_u128: Multiplies aDecimal128by au128integer value, returning an unscaledu128integer result.mul: Multiplies twoDecimal128numbers, returning aDecimal128result.div_u64: Divides aDecimal128by au64integer value, returning aDecimal128result.div: Divides aDecimal128by au128integer value, returning aDecimal128result.val: Retrieves the inner value of theDecimal128(which is scaled by 1e18).is_same: Compares twoDecimal128s.from_string: Parses a number into aDecimal128.
And these functions are implemented in decimal256:
new: Creates aDecimal256from a (premultiplied)u256value.new_u64: Creates aDecimal256from a (premultiplied)u64value.new_u128: Creates aDecimal256from a (premultiplied)u128value.one: Creates aDecimal256with value 1.zero: Creates aDecimal256with zero value.from_ratio_u64: Creates aDecimal256that represents the ratio between twou64integers.from_ratio_u128: Creates aDecimal256that represents the ratio between twou128integers.from_ratio: Creates aDecimal256that represents the ratio between twou256integers.add: Adds twoDecimal256, returning a newDecimal256as a result.sub: Adds twoDecimal256, returning a newDecimal256as a result.mul_u64: Multiplies aDecimal256by au64integer value, returning an unscaledu64integer result.mul_u128: Multiplies aDecimal256by au128integer value, returning an unscaledu128integer result.mul_u256: Multiplies aDecimal256by au256integer value, returning an unscaledu256integer result.mul: Multiplies twoDecimal256numbers, returning aDecimal256result.div_u64: Divides aDecimal256by au64integer value, returning aDecimal256result.div_u128: Divides aDecimal256by au128integer value, returning aDecimal256result.div: Divides aDecimal256by au256integer value, returning aDecimal256result.val: Retrieves the inner value of theDecimal256(which is scaled by 1e18).is_same: Compares twoDecimal256s.from_string: Parses a number into aDecimal256.