pub struct XFL(pub i64);
Expand description
Abstraction of XFL floating point numbers. The struct is overloaded with basic numeric operations, such as addition, subtraction, multiplication, division, and negation. Comparison operators are also implemented.
Tuple Fields§
§0: i64
Implementations§
Source§impl XFL
impl XFL
Sourcepub fn new(exponent: i32, mantissa: i64) -> Result<Self>
pub fn new(exponent: i32, mantissa: i64) -> Result<Self>
Create a new XFL number from an exponent and mantissa
§Example
let plus_1000 = XFL::new(-12, 1000000000000000).unwrap_line_number();
Sourcepub fn from_sto(serialized_xfl: &[u8; 8]) -> Result<Self>
pub fn from_sto(serialized_xfl: &[u8; 8]) -> Result<Self>
Read a serialized XFL amount into an XFL
Sourcepub fn one() -> Self
pub fn one() -> Self
Return the number 1 represented in an XFL enclosing number
§Example
let half = XFL::one().mulratio(false, 1, 2)
Sourcepub fn to_int64(&self, decimal_places: u32, is_absolute: bool) -> Result<i64>
pub fn to_int64(&self, decimal_places: u32, is_absolute: bool) -> Result<i64>
Convert an XFL floating point into an integer (floor). The behavior is as follows:
- Left shift (multiply by 10) the XFL by the number of specified decimal places
- Convert the resulting XFL to an integer, discarding any remainder
- Return the integer
§Example
let approx_pi = XFL::new(-15, 3140000000000000).unwrap_line_number();
if 3 != approx_pi.to_int64(0, false).unwrap_line_number() {
rollback(b"incorect rounding", line!().into());
}
Sourcepub fn exponent(&self) -> i64
pub fn exponent(&self) -> i64
Get the exponent of an XFL enclosing number
§Example
let plus_998 = XFL::new(-13, 9980000000000000).unwrap_line_number();
if plus_998.exponent() != -13 {
rollback(b"exponent incorrect", line!().into());
}
Sourcepub fn mantissa(&self) -> i64
pub fn mantissa(&self) -> i64
Get the exponent of an XFL enclosing number
§Example
let plus_998 = XFL::new(-13, 9980000000000000).unwrap_line_number();
if plus_998.mantissa() != 9980000000000000 {
rollback(b"mantissa incorrect", line!().into());
}
Sourcepub fn mulratio(
&self,
round_up: bool,
numerator: u32,
denominator: u32,
) -> Result<XFL>
pub fn mulratio( &self, round_up: bool, numerator: u32, denominator: u32, ) -> Result<XFL>
Multiply an XFL floating point by a non-XFL numerator and denominator
§Example
if XFL::one().mulratio(false, 1, 2).unwrap_line_number()
!= XFL::one().mulratio(false, 5, 10).unwrap_line_number()
{
rollback(b"", line!().into());
}
Trait Implementations§
Source§impl PartialOrd for XFL
impl PartialOrd for XFL
impl Copy for XFL
Auto Trait Implementations§
impl Freeze for XFL
impl RefUnwindSafe for XFL
impl Send for XFL
impl Sync for XFL
impl Unpin for XFL
impl UnwindSafe for XFL
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more