Struct psy_math::Number128

source ·
pub struct Number128(_);
Expand description

A fixed-point decimal number 128 bits wide

Implementations§

source§

impl Number128

source

pub const ONE: Self = _

source

pub const ZERO: Self = _

source

pub const MAX: Self = _

source

pub const MIN: Self = _

source

pub const BITS: u32 = 128u32

source

pub fn as_u64(&self, exponent: impl Into<i32>) -> u64

Convert this number to fit in a u64

The precision of the number in the u64 is based on the exponent provided.

source

pub fn as_f64(&self) -> f64

Convert this number to a f64

source

pub fn from_decimal(value: impl Into<i128>, exponent: impl Into<i32>) -> Self

Convert another integer

source

pub fn from_bps(basis_points: u16) -> Self

Convert from basis points

source

pub fn into_bits(self) -> [u8; 16]

Get the underlying 128-bit representation in bytes. Uses the target endianness of the caller

source

pub fn from_bits(bits: [u8; 16]) -> Self

Read a number from a raw 128-bit representation, which was previously returned by a call to into_bits. Uses the target endianness of the caller

source

pub fn to_i128(self) -> i128

Get the underlying i128 value

source

pub fn from_i128(value: i128) -> Self

Create Number128 from an i128

Trait Implementations§

source§

impl Add<Number128> for Number128

§

type Output = Number128

The resulting type after applying the + operator.
source§

fn add(self, rhs: Number128) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign<Number128> for Number128

source§

fn add_assign(&mut self, rhs: Number128)

Performs the += operation. Read more
source§

impl Clone for Number128

source§

fn clone(&self) -> Number128

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 Debug for Number128

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Number128

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Div<Number128> for Number128

§

type Output = Number128

The resulting type after applying the / operator.
source§

fn div(self, rhs: Number128) -> Self::Output

Performs the / operation. Read more
source§

impl<T: Into<i128>> Div<T> for Number128

§

type Output = Number128

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
source§

impl DivAssign<Number128> for Number128

source§

fn div_assign(&mut self, rhs: Number128)

Performs the /= operation. Read more
source§

impl<T: Into<i128>> From<T> for Number128

source§

fn from(n: T) -> Self

Converts to this type from the input type.
source§

impl Mul<Number128> for Number128

§

type Output = Number128

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Number128) -> Self::Output

Performs the * operation. Read more
source§

impl<T: Into<i128>> Mul<T> for Number128

§

type Output = Number128

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
source§

impl MulAssign<Number128> for Number128

source§

fn mul_assign(&mut self, rhs: Number128)

Performs the *= operation. Read more
source§

impl Neg for Number128

§

type Output = Number128

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Ord for Number128

source§

fn cmp(&self, other: &Number128) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Number128> for Number128

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Number128> for Number128

source§

fn partial_cmp(&self, other: &Number128) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<Number128> for Number128

§

type Output = Number128

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Number128) -> Self::Output

Performs the - operation. Read more
source§

impl SubAssign<Number128> for Number128

source§

fn sub_assign(&mut self, rhs: Number128)

Performs the -= operation. Read more
source§

impl Zeroable for Number128

source§

fn zeroed() -> Self

source§

impl Copy for Number128

source§

impl Eq for Number128

source§

impl Pod for Number128

source§

impl StructuralEq for Number128

source§

impl StructuralPartialEq for Number128

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CheckedBitPattern for Twhere T: AnyBitPattern,

§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> AnyBitPattern for Twhere T: Pod,

source§

impl<T> NoUninit for Twhere T: Pod,