hooks_rs::api

Struct XFL

Source
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

Source

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();
Source

pub fn from_sto(serialized_xfl: &[u8; 8]) -> Result<Self>

Read a serialized XFL amount into an XFL

Source

pub fn one() -> Self

Return the number 1 represented in an XFL enclosing number

§Example
let half = XFL::one().mulratio(false, 1, 2)
Source

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:

  1. Left shift (multiply by 10) the XFL by the number of specified decimal places
  2. Convert the resulting XFL to an integer, discarding any remainder
  3. 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());
}
Source

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());
}
Source

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());
}
Source

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 Add for XFL

Source§

type Output = Result<XFL>

The resulting type after applying the + operator.
Source§

fn add(self, other: XFL) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for XFL

Source§

fn clone(&self) -> XFL

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Div for XFL

Source§

type Output = Result<XFL>

The resulting type after applying the / operator.
Source§

fn div(self, other: XFL) -> Self::Output

Performs the / operation. Read more
Source§

impl Mul for XFL

Source§

type Output = Result<XFL>

The resulting type after applying the * operator.
Source§

fn mul(self, other: XFL) -> Self::Output

Performs the * operation. Read more
Source§

impl Neg for XFL

Source§

type Output = Result<XFL>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for XFL

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for XFL

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for XFL

Source§

type Output = Result<XFL>

The resulting type after applying the - operator.
Source§

fn sub(self, other: XFL) -> Self::Output

Performs the - operation. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.