Struct fix::Fix
[−]
[src]
pub struct Fix<Bits, Base, Exp> { pub bits: Bits, // some fields omitted }
Fixed-point number representing Bits × Base Exp.
Bits
is an integer primitive type, or any type which can be created from a type-level integer and exponentiated.Base
is anUnsigned
type-level integer.Exp
is a signed type-levelInteger
.
Summary of operations
Lower case variables represent values of Bits. Upper case B and E represent type-level integers Base and Exp, respectively.
- −(x BE) = (−x) BE
- (x BE) + (y BE) = (x + y) BE
- (x BE) − (y BE) = (x − y) BE
- (x BEx) × (y BEy) = (x × y) BEx + Ey
- (x BEx) ÷ (y BEy) = (x ÷ y) BEx − Ey
- (x BEx) % (y BEy) = (x % y) BEx
- (x BE) × y = (x × y) BE
- (x BE) ÷ y = (x ÷ y) BE
- (x BE) % y = (x % y) BE
Fields
bits: Bits
The underlying integer.
Methods
impl<Bits, Base, Exp> Fix<Bits, Base, Exp>
[src]
fn new(bits: Bits) -> Self
[src]
Creates a number.
Examples
use fix::aliases::si::{Kilo, Milli}; Milli::new(25); // 0.025 Kilo::new(25); // 25 000
fn convert<ToExp>(self) -> Fix<Bits, Base, ToExp> where
Bits: FromUnsigned + Pow + Mul<Output = Bits> + Div<Output = Bits>,
Base: Unsigned,
Exp: Sub<ToExp>,
Diff<Exp, ToExp>: Abs + IsLess<Z0>,
AbsVal<Diff<Exp, ToExp>>: Integer,
[src]
Bits: FromUnsigned + Pow + Mul<Output = Bits> + Div<Output = Bits>,
Base: Unsigned,
Exp: Sub<ToExp>,
Diff<Exp, ToExp>: Abs + IsLess<Z0>,
AbsVal<Diff<Exp, ToExp>>: Integer,
Converts to another Exp.
Examples
use fix::aliases::si::{Kilo, Milli}; let kilo = Kilo::new(5); let milli = Milli::new(5_000_000); assert_eq!(kilo, milli.convert()); assert_eq!(milli, kilo.convert());
Trait Implementations
impl<Bits, Base, Exp> Copy for Fix<Bits, Base, Exp> where
Bits: Copy,
[src]
Bits: Copy,
impl<Bits, Base, Exp> Clone for Fix<Bits, Base, Exp> where
Bits: Clone,
[src]
Bits: Clone,
fn clone(&self) -> Self
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<Bits, Base, Exp> Default for Fix<Bits, Base, Exp> where
Bits: Default,
[src]
Bits: Default,
impl<Bits, Base, Exp> Hash for Fix<Bits, Base, Exp> where
Bits: Hash,
[src]
Bits: Hash,
fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<Bits, Base, Exp> Debug for Fix<Bits, Base, Exp> where
Bits: Debug,
Base: Unsigned,
Exp: Integer,
[src]
Bits: Debug,
Base: Unsigned,
Exp: Integer,
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<Bits, Base, Exp> Eq for Fix<Bits, Base, Exp> where
Bits: Eq,
[src]
Bits: Eq,
impl<Bits, Base, Exp> PartialEq for Fix<Bits, Base, Exp> where
Bits: PartialEq,
[src]
Bits: PartialEq,
fn eq(&self, rhs: &Self) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<Bits, Base, Exp> PartialOrd for Fix<Bits, Base, Exp> where
Bits: PartialOrd,
[src]
Bits: PartialOrd,
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<Bits, Base, Exp> Ord for Fix<Bits, Base, Exp> where
Bits: Ord,
[src]
Bits: Ord,
fn cmp(&self, rhs: &Self) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl<Bits, Base, Exp> Neg for Fix<Bits, Base, Exp> where
Bits: Neg<Output = Bits>,
[src]
Bits: Neg<Output = Bits>,
type Output = Self
The resulting type after applying the -
operator.
fn neg(self) -> Self
[src]
Performs the unary -
operation.
impl<Bits, Base, Exp> Add for Fix<Bits, Base, Exp> where
Bits: Add<Output = Bits>,
[src]
Bits: Add<Output = Bits>,
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self
[src]
Performs the +
operation.
impl<Bits, Base, Exp> Sub for Fix<Bits, Base, Exp> where
Bits: Sub<Output = Bits>,
[src]
Bits: Sub<Output = Bits>,
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Self
[src]
Performs the -
operation.
impl<Bits, Base, LExp, RExp> Mul<Fix<Bits, Base, RExp>> for Fix<Bits, Base, LExp> where
Bits: Mul<Output = Bits>,
LExp: Add<RExp>,
[src]
Bits: Mul<Output = Bits>,
LExp: Add<RExp>,
type Output = Fix<Bits, Base, Sum<LExp, RExp>>
The resulting type after applying the *
operator.
fn mul(self, rhs: Fix<Bits, Base, RExp>) -> Self::Output
[src]
Performs the *
operation.
impl<Bits, Base, LExp, RExp> Div<Fix<Bits, Base, RExp>> for Fix<Bits, Base, LExp> where
Bits: Div<Output = Bits>,
LExp: Sub<RExp>,
[src]
Bits: Div<Output = Bits>,
LExp: Sub<RExp>,
type Output = Fix<Bits, Base, Diff<LExp, RExp>>
The resulting type after applying the /
operator.
fn div(self, rhs: Fix<Bits, Base, RExp>) -> Self::Output
[src]
Performs the /
operation.
impl<Bits, Base, Exp> Rem for Fix<Bits, Base, Exp> where
Bits: Rem<Output = Bits>,
[src]
Bits: Rem<Output = Bits>,
type Output = Self
The resulting type after applying the %
operator.
fn rem(self, rhs: Self) -> Self
[src]
Performs the %
operation.
impl<Bits, Base, Exp> Mul<Bits> for Fix<Bits, Base, Exp> where
Bits: Mul<Output = Bits>,
[src]
Bits: Mul<Output = Bits>,
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: Bits) -> Self
[src]
Performs the *
operation.
impl<Bits, Base, Exp> Div<Bits> for Fix<Bits, Base, Exp> where
Bits: Div<Output = Bits>,
[src]
Bits: Div<Output = Bits>,
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: Bits) -> Self
[src]
Performs the /
operation.
impl<Bits, Base, Exp> Rem<Bits> for Fix<Bits, Base, Exp> where
Bits: Rem<Output = Bits>,
[src]
Bits: Rem<Output = Bits>,
type Output = Self
The resulting type after applying the %
operator.
fn rem(self, rhs: Bits) -> Self
[src]
Performs the %
operation.
impl<Bits, Base, Exp> AddAssign for Fix<Bits, Base, Exp> where
Bits: AddAssign,
[src]
Bits: AddAssign,
fn add_assign(&mut self, rhs: Self)
[src]
Performs the +=
operation.
impl<Bits, Base, Exp> SubAssign for Fix<Bits, Base, Exp> where
Bits: SubAssign,
[src]
Bits: SubAssign,
fn sub_assign(&mut self, rhs: Self)
[src]
Performs the -=
operation.
impl<Bits, Base, Exp> MulAssign<Bits> for Fix<Bits, Base, Exp> where
Bits: MulAssign,
[src]
Bits: MulAssign,
fn mul_assign(&mut self, rhs: Bits)
[src]
Performs the *=
operation.
impl<Bits, Base, Exp> DivAssign<Bits> for Fix<Bits, Base, Exp> where
Bits: DivAssign,
[src]
Bits: DivAssign,
fn div_assign(&mut self, rhs: Bits)
[src]
Performs the /=
operation.
impl<Bits, Base, LExp, RExp> RemAssign<Fix<Bits, Base, RExp>> for Fix<Bits, Base, LExp> where
Bits: RemAssign,
[src]
Bits: RemAssign,
fn rem_assign(&mut self, rhs: Fix<Bits, Base, RExp>)
[src]
Performs the %=
operation.
impl<Bits, Base, Exp> RemAssign<Bits> for Fix<Bits, Base, Exp> where
Bits: RemAssign,
[src]
Bits: RemAssign,
fn rem_assign(&mut self, rhs: Bits)
[src]
Performs the %=
operation.