pub type Rational8 = Ratio<Sign, u8, u8>;Expand description
A signed ratio between two small integers.
Aliased Type§
pub struct Rational8 { /* private fields */ }Implementations§
Source§impl Rational8
impl Rational8
Sourcepub fn new(numerator: i8, denominator: u8) -> Option<Self>
pub fn new(numerator: i8, denominator: u8) -> Option<Self>
A ratio in lowest terms, or None when the denominator is zero.
§Range
The magnitude of this type is stored unsigned, while this constructor takes a
signed numerator of the same width. A Rational8 therefore represents every value
from -255 to 255, but this constructor only reaches -128 to 127; the values
in between are reached by FromStr, by
FromPrimitive from a wider primitive, and by
arithmetic. They are representable but not convertible back:
to_i8 returns None for them, because an i8
is what doesn’t fit, not the ratio.
Sourcepub fn new_signed<T: Into<Sign>>(
sign: T,
numerator: u8,
denominator: u8,
) -> Option<Self>
pub fn new_signed<T: Into<Sign>>( sign: T, numerator: u8, denominator: u8, ) -> Option<Self>
A ratio in lowest terms from a sign and a magnitude.
§Return value
None when the arguments describe no number: the denominator has to be nonzero,
and the sign has to be [Sign::Zero] exactly when the numerator is zero. These
invariants used to be checked with debug_assert! only, which let a release build
construct a ratio with a zero denominator; Big::new_signed returns an Option
for the same reason.
Trait Implementations§
Source§impl<N> Absorb<&N> for Rational8
A provider that hands out references to what it stores is read through them.
impl<N> Absorb<&N> for Rational8
A provider that hands out references to what it stores is read through them.
Source§fn from_narrow(narrow: &&N) -> Self
fn from_narrow(narrow: &&N) -> Self
Source§fn add_narrow(&mut self, narrow: &&N)
fn add_narrow(&mut self, narrow: &&N)
Source§fn sub_narrow(&mut self, narrow: &&N)
fn sub_narrow(&mut self, narrow: &&N)
Source§fn mul_narrow(&self, narrow: &&N) -> Self
fn mul_narrow(&self, narrow: &&N) -> Self
Source§fn add_mul_narrow(&mut self, narrow: &&N, other: &Self)
fn add_mul_narrow(&mut self, narrow: &&N, other: &Self)
Source§impl Absorb<Binary> for Rational8
impl Absorb<Binary> for Rational8
Source§fn from_narrow(narrow: &Binary) -> Self
fn from_narrow(narrow: &Binary) -> Self
Source§fn add_narrow(&mut self, narrow: &Binary)
fn add_narrow(&mut self, narrow: &Binary)
Source§fn sub_narrow(&mut self, narrow: &Binary)
fn sub_narrow(&mut self, narrow: &Binary)
Source§fn mul_narrow(&self, narrow: &Binary) -> Self
fn mul_narrow(&self, narrow: &Binary) -> Self
Source§fn add_mul_narrow(&mut self, narrow: &Binary, other: &Self)
fn add_mul_narrow(&mut self, narrow: &Binary, other: &Self)
Source§impl Absorb<One> for Rational8
impl Absorb<One> for Rational8
Source§fn from_narrow(_: &One) -> Self
fn from_narrow(_: &One) -> Self
Source§fn add_narrow(&mut self, _: &One)
fn add_narrow(&mut self, _: &One)
Source§fn sub_narrow(&mut self, _: &One)
fn sub_narrow(&mut self, _: &One)
Source§fn mul_narrow(&self, _: &One) -> Self
fn mul_narrow(&self, _: &One) -> Self
Source§fn add_mul_narrow(&mut self, _: &One, other: &Self)
fn add_mul_narrow(&mut self, _: &One, other: &Self)
Source§impl<N> Absorb<Option<N>> for Rational8
An absent value is zero, so it contributes nothing.
impl<N> Absorb<Option<N>> for Rational8
An absent value is zero, so it contributes nothing.
Source§fn from_narrow(narrow: &Option<N>) -> Self
fn from_narrow(narrow: &Option<N>) -> Self
Source§fn add_narrow(&mut self, narrow: &Option<N>)
fn add_narrow(&mut self, narrow: &Option<N>)
Source§fn sub_narrow(&mut self, narrow: &Option<N>)
fn sub_narrow(&mut self, narrow: &Option<N>)
Source§fn mul_narrow(&self, narrow: &Option<N>) -> Self
fn mul_narrow(&self, narrow: &Option<N>) -> Self
Source§fn add_mul_narrow(&mut self, narrow: &Option<N>, other: &Self)
fn add_mul_narrow(&mut self, narrow: &Option<N>, other: &Self)
Source§impl Absorb<SignedOne> for Rational8
impl Absorb<SignedOne> for Rational8
Source§fn from_narrow(narrow: &SignedOne) -> Self
fn from_narrow(narrow: &SignedOne) -> Self
Source§fn add_narrow(&mut self, narrow: &SignedOne)
fn add_narrow(&mut self, narrow: &SignedOne)
Source§fn sub_narrow(&mut self, narrow: &SignedOne)
fn sub_narrow(&mut self, narrow: &SignedOne)
Source§fn mul_narrow(&self, narrow: &SignedOne) -> Self
fn mul_narrow(&self, narrow: &SignedOne) -> Self
Source§fn add_mul_narrow(&mut self, narrow: &SignedOne, other: &Self)
fn add_mul_narrow(&mut self, narrow: &SignedOne, other: &Self)
Source§impl Absorb<Zero> for Rational8
impl Absorb<Zero> for Rational8
Source§fn from_narrow(_: &Zero) -> Self
fn from_narrow(_: &Zero) -> Self
Source§fn add_narrow(&mut self, _: &Zero)
fn add_narrow(&mut self, _: &Zero)
Source§fn sub_narrow(&mut self, _: &Zero)
fn sub_narrow(&mut self, _: &Zero)
Source§fn mul_narrow(&self, _: &Zero) -> Self
fn mul_narrow(&self, _: &Zero) -> Self
Source§fn add_mul_narrow(&mut self, _: &Zero, _: &Self)
fn add_mul_narrow(&mut self, _: &Zero, _: &Self)
Source§impl Absorb<i8> for Rational8
impl Absorb<i8> for Rational8
Source§fn from_narrow(narrow: &i8) -> Self
fn from_narrow(narrow: &i8) -> Self
Source§fn add_narrow(&mut self, narrow: &i8)
fn add_narrow(&mut self, narrow: &i8)
Source§fn sub_narrow(&mut self, narrow: &i8)
fn sub_narrow(&mut self, narrow: &i8)
Source§fn mul_narrow(&self, narrow: &i8) -> Self
fn mul_narrow(&self, narrow: &i8) -> Self
Source§fn add_mul_narrow(&mut self, narrow: &i8, other: &Self)
fn add_mul_narrow(&mut self, narrow: &i8, other: &Self)
Source§impl Absorb<u8> for Rational8
impl Absorb<u8> for Rational8
Source§fn from_narrow(narrow: &u8) -> Self
fn from_narrow(narrow: &u8) -> Self
Source§fn add_narrow(&mut self, narrow: &u8)
fn add_narrow(&mut self, narrow: &u8)
Source§fn sub_narrow(&mut self, narrow: &u8)
fn sub_narrow(&mut self, narrow: &u8)
Source§fn mul_narrow(&self, narrow: &u8) -> Self
fn mul_narrow(&self, narrow: &u8) -> Self
Source§fn add_mul_narrow(&mut self, narrow: &u8, other: &Self)
fn add_mul_narrow(&mut self, narrow: &u8, other: &Self)
Source§impl AddAssign for Rational8
impl AddAssign for Rational8
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl AddAssign<&NonZero<i8>> for Rational8
impl AddAssign<&NonZero<i8>> for Rational8
Source§fn add_assign(&mut self, rhs: &NonZeroI8)
fn add_assign(&mut self, rhs: &NonZeroI8)
+= operation. Read moreSource§impl AddAssign<&NonZero<u8>> for Rational8
impl AddAssign<&NonZero<u8>> for Rational8
Source§fn add_assign(&mut self, rhs: &NonZeroU8)
fn add_assign(&mut self, rhs: &NonZeroU8)
+= operation. Read moreSource§impl AddAssign<&One> for Rational8
impl AddAssign<&One> for Rational8
Source§fn add_assign(&mut self, _: &One)
fn add_assign(&mut self, _: &One)
+= operation. Read moreSource§impl AddAssign<&Zero> for Rational8
impl AddAssign<&Zero> for Rational8
Source§fn add_assign(&mut self, _: &Zero)
fn add_assign(&mut self, _: &Zero)
+= operation. Read moreSource§impl AddAssign<&i8> for Rational8
impl AddAssign<&i8> for Rational8
Source§fn add_assign(&mut self, rhs: &i8)
fn add_assign(&mut self, rhs: &i8)
+= operation. Read moreSource§impl AddAssign<&u8> for Rational8
impl AddAssign<&u8> for Rational8
Source§fn add_assign(&mut self, rhs: &u8)
fn add_assign(&mut self, rhs: &u8)
+= operation. Read moreSource§impl AddAssign<NonZero<i8>> for Rational8
impl AddAssign<NonZero<i8>> for Rational8
Source§fn add_assign(&mut self, rhs: NonZeroI8)
fn add_assign(&mut self, rhs: NonZeroI8)
+= operation. Read moreSource§impl AddAssign<NonZero<u8>> for Rational8
impl AddAssign<NonZero<u8>> for Rational8
Source§fn add_assign(&mut self, rhs: NonZeroU8)
fn add_assign(&mut self, rhs: NonZeroU8)
+= operation. Read moreSource§impl AddAssign<One> for Rational8
impl AddAssign<One> for Rational8
Source§fn add_assign(&mut self, _: One)
fn add_assign(&mut self, _: One)
+= operation. Read moreSource§impl AddAssign<Zero> for Rational8
impl AddAssign<Zero> for Rational8
Source§fn add_assign(&mut self, _: Zero)
fn add_assign(&mut self, _: Zero)
+= operation. Read moreSource§impl AddAssign<i8> for Rational8
impl AddAssign<i8> for Rational8
Source§fn add_assign(&mut self, rhs: i8)
fn add_assign(&mut self, rhs: i8)
+= operation. Read moreSource§impl AddAssign<u8> for Rational8
impl AddAssign<u8> for Rational8
Source§fn add_assign(&mut self, rhs: u8)
fn add_assign(&mut self, rhs: u8)
+= operation. Read moreSource§impl DivAssign for Rational8
impl DivAssign for Rational8
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl DivAssign<&NonZero<i8>> for Rational8
impl DivAssign<&NonZero<i8>> for Rational8
Source§fn div_assign(&mut self, rhs: &NonZeroI8)
fn div_assign(&mut self, rhs: &NonZeroI8)
/= operation. Read moreSource§impl DivAssign<&NonZero<u8>> for Rational8
impl DivAssign<&NonZero<u8>> for Rational8
Source§fn div_assign(&mut self, rhs: &NonZeroU8)
fn div_assign(&mut self, rhs: &NonZeroU8)
/= operation. Read moreSource§impl DivAssign<&One> for Rational8
impl DivAssign<&One> for Rational8
Source§fn div_assign(&mut self, _: &One)
fn div_assign(&mut self, _: &One)
/= operation. Read moreSource§impl DivAssign<&i8> for Rational8
impl DivAssign<&i8> for Rational8
Source§fn div_assign(&mut self, rhs: &i8)
fn div_assign(&mut self, rhs: &i8)
/= operation. Read moreSource§impl DivAssign<&u8> for Rational8
impl DivAssign<&u8> for Rational8
Source§fn div_assign(&mut self, rhs: &u8)
fn div_assign(&mut self, rhs: &u8)
/= operation. Read moreSource§impl DivAssign<NonZero<i8>> for Rational8
impl DivAssign<NonZero<i8>> for Rational8
Source§fn div_assign(&mut self, rhs: NonZeroI8)
fn div_assign(&mut self, rhs: NonZeroI8)
/= operation. Read moreSource§impl DivAssign<NonZero<u8>> for Rational8
impl DivAssign<NonZero<u8>> for Rational8
Source§fn div_assign(&mut self, rhs: NonZeroU8)
fn div_assign(&mut self, rhs: NonZeroU8)
/= operation. Read moreSource§impl DivAssign<One> for Rational8
impl DivAssign<One> for Rational8
Source§fn div_assign(&mut self, _: One)
fn div_assign(&mut self, _: One)
/= operation. Read moreSource§impl DivAssign<i8> for Rational8
impl DivAssign<i8> for Rational8
Source§fn div_assign(&mut self, rhs: i8)
fn div_assign(&mut self, rhs: i8)
/= operation. Read moreSource§impl DivAssign<u8> for Rational8
impl DivAssign<u8> for Rational8
Source§fn div_assign(&mut self, rhs: u8)
fn div_assign(&mut self, rhs: u8)
/= operation. Read moreSource§impl EncodingSize for Rational8
impl EncodingSize for Rational8
Source§fn numerator_bits(&self) -> u32
fn numerator_bits(&self) -> u32
Source§fn denominator_bits(&self) -> u32
fn denominator_bits(&self) -> u32
Source§fn encoding_bits(&self) -> u64
fn encoding_bits(&self) -> u64
impl Eq for Rational8
Source§impl FromPrimitive for Rational8
impl FromPrimitive for Rational8
Source§fn from_i128(n: i128) -> Option<Self>
fn from_i128(n: i128) -> Option<Self>
The default implementation goes through from_i64,
which discards every value that only a wider magnitude type can hold.
Source§fn from_u128(n: u128) -> Option<Self>
fn from_u128(n: u128) -> Option<Self>
The default implementation goes through from_u64,
which discards every value that only a wider magnitude type can hold.
Source§fn from_i64(n: i64) -> Option<Self>
fn from_i64(n: i64) -> Option<Self>
i64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u64(n: u64) -> Option<Self>
fn from_u64(n: u64) -> Option<Self>
u64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_f32(n: f32) -> Option<Self>
fn from_f32(n: f32) -> Option<Self>
f32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_f64(n: f64) -> Option<Self>
fn from_f64(n: f64) -> Option<Self>
f64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read moreSource§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
i8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
i16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i32(n: i32) -> Option<Self>
fn from_i32(n: i32) -> Option<Self>
i32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: u8) -> Option<Self>
u8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§impl MulAssign for Rational8
impl MulAssign for Rational8
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl MulAssign<&NonZero<i8>> for Rational8
impl MulAssign<&NonZero<i8>> for Rational8
Source§fn mul_assign(&mut self, rhs: &NonZeroI8)
fn mul_assign(&mut self, rhs: &NonZeroI8)
*= operation. Read moreSource§impl MulAssign<&NonZero<u8>> for Rational8
impl MulAssign<&NonZero<u8>> for Rational8
Source§fn mul_assign(&mut self, rhs: &NonZeroU8)
fn mul_assign(&mut self, rhs: &NonZeroU8)
*= operation. Read moreSource§impl MulAssign<&One> for Rational8
impl MulAssign<&One> for Rational8
Source§fn mul_assign(&mut self, _: &One)
fn mul_assign(&mut self, _: &One)
*= operation. Read moreSource§impl MulAssign<&Zero> for Rational8
impl MulAssign<&Zero> for Rational8
Source§fn mul_assign(&mut self, _: &Zero)
fn mul_assign(&mut self, _: &Zero)
*= operation. Read moreSource§impl MulAssign<&i8> for Rational8
impl MulAssign<&i8> for Rational8
Source§fn mul_assign(&mut self, rhs: &i8)
fn mul_assign(&mut self, rhs: &i8)
*= operation. Read moreSource§impl MulAssign<&u8> for Rational8
impl MulAssign<&u8> for Rational8
Source§fn mul_assign(&mut self, rhs: &u8)
fn mul_assign(&mut self, rhs: &u8)
*= operation. Read moreSource§impl MulAssign<NonZero<i8>> for Rational8
impl MulAssign<NonZero<i8>> for Rational8
Source§fn mul_assign(&mut self, rhs: NonZeroI8)
fn mul_assign(&mut self, rhs: NonZeroI8)
*= operation. Read moreSource§impl MulAssign<NonZero<u8>> for Rational8
impl MulAssign<NonZero<u8>> for Rational8
Source§fn mul_assign(&mut self, rhs: NonZeroU8)
fn mul_assign(&mut self, rhs: NonZeroU8)
*= operation. Read moreSource§impl MulAssign<One> for Rational8
impl MulAssign<One> for Rational8
Source§fn mul_assign(&mut self, _: One)
fn mul_assign(&mut self, _: One)
*= operation. Read moreSource§impl MulAssign<Zero> for Rational8
impl MulAssign<Zero> for Rational8
Source§fn mul_assign(&mut self, _: Zero)
fn mul_assign(&mut self, _: Zero)
*= operation. Read moreSource§impl MulAssign<i8> for Rational8
impl MulAssign<i8> for Rational8
Source§fn mul_assign(&mut self, rhs: i8)
fn mul_assign(&mut self, rhs: i8)
*= operation. Read moreSource§impl MulAssign<u8> for Rational8
impl MulAssign<u8> for Rational8
Source§fn mul_assign(&mut self, rhs: u8)
fn mul_assign(&mut self, rhs: u8)
*= operation. Read moreSource§impl Ord for Rational8
impl Ord for Rational8
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Rational8
impl PartialOrd for Rational8
Source§impl SubAssign for Rational8
impl SubAssign for Rational8
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreSource§impl SubAssign<&NonZero<i8>> for Rational8
impl SubAssign<&NonZero<i8>> for Rational8
Source§fn sub_assign(&mut self, rhs: &NonZeroI8)
fn sub_assign(&mut self, rhs: &NonZeroI8)
-= operation. Read moreSource§impl SubAssign<&NonZero<u8>> for Rational8
impl SubAssign<&NonZero<u8>> for Rational8
Source§fn sub_assign(&mut self, rhs: &NonZeroU8)
fn sub_assign(&mut self, rhs: &NonZeroU8)
-= operation. Read moreSource§impl SubAssign<&One> for Rational8
impl SubAssign<&One> for Rational8
Source§fn sub_assign(&mut self, _: &One)
fn sub_assign(&mut self, _: &One)
-= operation. Read moreSource§impl SubAssign<&i8> for Rational8
impl SubAssign<&i8> for Rational8
Source§fn sub_assign(&mut self, rhs: &i8)
fn sub_assign(&mut self, rhs: &i8)
-= operation. Read moreSource§impl SubAssign<&u8> for Rational8
impl SubAssign<&u8> for Rational8
Source§fn sub_assign(&mut self, rhs: &u8)
fn sub_assign(&mut self, rhs: &u8)
-= operation. Read moreSource§impl SubAssign<NonZero<i8>> for Rational8
impl SubAssign<NonZero<i8>> for Rational8
Source§fn sub_assign(&mut self, rhs: NonZeroI8)
fn sub_assign(&mut self, rhs: NonZeroI8)
-= operation. Read moreSource§impl SubAssign<NonZero<u8>> for Rational8
impl SubAssign<NonZero<u8>> for Rational8
Source§fn sub_assign(&mut self, rhs: NonZeroU8)
fn sub_assign(&mut self, rhs: NonZeroU8)
-= operation. Read moreSource§impl SubAssign<One> for Rational8
impl SubAssign<One> for Rational8
Source§fn sub_assign(&mut self, _: One)
fn sub_assign(&mut self, _: One)
-= operation. Read moreSource§impl SubAssign<Zero> for Rational8
impl SubAssign<Zero> for Rational8
Source§fn sub_assign(&mut self, _: Zero)
fn sub_assign(&mut self, _: Zero)
-= operation. Read moreSource§impl SubAssign<i8> for Rational8
impl SubAssign<i8> for Rational8
Source§fn sub_assign(&mut self, rhs: i8)
fn sub_assign(&mut self, rhs: i8)
-= operation. Read moreSource§impl SubAssign<u8> for Rational8
impl SubAssign<u8> for Rational8
Source§fn sub_assign(&mut self, rhs: u8)
fn sub_assign(&mut self, rhs: u8)
-= operation. Read moreSource§impl ToPrimitive for Rational8
impl ToPrimitive for Rational8
Source§fn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
self to an isize. If the value cannot be
represented by an isize, then None is returned.Source§fn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
self to an i8. If the value cannot be
represented by an i8, then None is returned.Source§fn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
self to an i16. If the value cannot be
represented by an i16, then None is returned.Source§fn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
self to an i32. If the value cannot be
represented by an i32, then None is returned.Source§fn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
self to an i64. If the value cannot be
represented by an i64, then None is returned.Source§fn to_i128(&self) -> Option<i128>
fn to_i128(&self) -> Option<i128>
self to an i128. If the value cannot be
represented by an i128 (i64 under the default implementation), then
None is returned. Read moreSource§fn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
self to a usize. If the value cannot be
represented by a usize, then None is returned.Source§fn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
self to a u8. If the value cannot be
represented by a u8, then None is returned.Source§fn to_u16(&self) -> Option<u16>
fn to_u16(&self) -> Option<u16>
self to a u16. If the value cannot be
represented by a u16, then None is returned.Source§fn to_u32(&self) -> Option<u32>
fn to_u32(&self) -> Option<u32>
self to a u32. If the value cannot be
represented by a u32, then None is returned.Source§fn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
self to a u64. If the value cannot be
represented by a u64, then None is returned.Source§fn to_u128(&self) -> Option<u128>
fn to_u128(&self) -> Option<u128>
self to a u128. If the value cannot be
represented by a u128 (u64 under the default implementation), then
None is returned. Read more