pub struct Fix<Bits, Base, Exp> {
pub bits: Bits,
/* private fields */
}
Expand description
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.
Implementations§
Source§impl<Bits, Base, Exp> Fix<Bits, Base, Exp>
impl<Bits, Base, Exp> Fix<Bits, Base, Exp>
Sourcepub fn new(bits: Bits) -> Self
pub fn new(bits: Bits) -> Self
Creates a number.
§Examples
use fix::aliases::si::{Kilo, Milli};
Milli::new(25); // 0.025
Kilo::new(25); // 25 000
Trait Implementations§
Source§impl<Bits, Base, Exp> AddAssign for Fix<Bits, Base, Exp>where
Bits: AddAssign,
impl<Bits, Base, Exp> AddAssign for Fix<Bits, Base, Exp>where
Bits: AddAssign,
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
operation. Read moreSource§impl<Bits, Base, Exp> DivAssign<Bits> for Fix<Bits, Base, Exp>where
Bits: DivAssign,
impl<Bits, Base, Exp> DivAssign<Bits> for Fix<Bits, Base, Exp>where
Bits: DivAssign,
Source§fn div_assign(&mut self, rhs: Bits)
fn div_assign(&mut self, rhs: Bits)
Performs the
/=
operation. Read moreSource§impl<Bits, Base, Exp> MulAssign<Bits> for Fix<Bits, Base, Exp>where
Bits: MulAssign,
impl<Bits, Base, Exp> MulAssign<Bits> for Fix<Bits, Base, Exp>where
Bits: MulAssign,
Source§fn mul_assign(&mut self, rhs: Bits)
fn mul_assign(&mut self, rhs: Bits)
Performs the
*=
operation. Read moreSource§impl<Bits, Base, Exp> Ord for Fix<Bits, Base, Exp>where
Bits: Ord,
impl<Bits, Base, Exp> Ord for Fix<Bits, Base, Exp>where
Bits: Ord,
Source§impl<Bits, Base, Exp> PartialOrd for Fix<Bits, Base, Exp>where
Bits: PartialOrd,
impl<Bits, Base, Exp> PartialOrd for Fix<Bits, Base, Exp>where
Bits: PartialOrd,
Source§impl<Bits, Base, Exp> RemAssign<Bits> for Fix<Bits, Base, Exp>where
Bits: RemAssign,
impl<Bits, Base, Exp> RemAssign<Bits> for Fix<Bits, Base, Exp>where
Bits: RemAssign,
Source§fn rem_assign(&mut self, rhs: Bits)
fn rem_assign(&mut self, rhs: Bits)
Performs the
%=
operation. Read moreSource§impl<Bits, Base, LExp, RExp> RemAssign<Fix<Bits, Base, RExp>> for Fix<Bits, Base, LExp>where
Bits: RemAssign,
impl<Bits, Base, LExp, RExp> RemAssign<Fix<Bits, Base, RExp>> for Fix<Bits, Base, LExp>where
Bits: RemAssign,
Source§fn rem_assign(&mut self, rhs: Fix<Bits, Base, RExp>)
fn rem_assign(&mut self, rhs: Fix<Bits, Base, RExp>)
Performs the
%=
operation. Read moreSource§impl<Bits, Base, Exp> SubAssign for Fix<Bits, Base, Exp>where
Bits: SubAssign,
impl<Bits, Base, Exp> SubAssign for Fix<Bits, Base, Exp>where
Bits: SubAssign,
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-=
operation. Read moreimpl<Bits, Base, Exp> Copy for Fix<Bits, Base, Exp>where
Bits: Copy,
impl<Bits, Base, Exp> Eq for Fix<Bits, Base, Exp>where
Bits: Eq,
Auto Trait Implementations§
impl<Bits, Base, Exp> Freeze for Fix<Bits, Base, Exp>where
Bits: Freeze,
impl<Bits, Base, Exp> RefUnwindSafe for Fix<Bits, Base, Exp>
impl<Bits, Base, Exp> Send for Fix<Bits, Base, Exp>
impl<Bits, Base, Exp> Sync for Fix<Bits, Base, Exp>
impl<Bits, Base, Exp> Unpin for Fix<Bits, Base, Exp>
impl<Bits, Base, Exp> UnwindSafe for Fix<Bits, Base, Exp>
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