Enum sp_arithmetic::per_things::Rounding
source · pub enum Rounding {
Up,
Down,
NearestPrefUp,
NearestPrefDown,
}Expand description
The rounding method to use for unsigned quantities.
Variants§
Implementations§
source§impl Rounding
impl Rounding
sourcepub const fn from_signed(rounding: SignedRounding, negative: bool) -> Self
pub const fn from_signed(rounding: SignedRounding, negative: bool) -> Self
Returns the value for Rounding which would give the same result ignorant of the sign.
Examples found in repository?
src/fixed_point.rs (line 158)
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
fn checked_from_rational<N: FixedPointOperand, D: FixedPointOperand>(
n: N,
d: D,
) -> Option<Self> {
if d == D::zero() {
return None
}
let n: I129 = n.into();
let d: I129 = d.into();
let negative = n.negative != d.negative;
multiply_by_rational_with_rounding(
n.value,
Self::DIV.unique_saturated_into(),
d.value,
Rounding::from_signed(SignedRounding::Minor, negative),
)
.and_then(|value| from_i129(I129 { value, negative }))
.map(Self::from_inner)
}
/// Checked multiplication for integer type `N`. Equal to `self * n`.
///
/// Returns `None` if the result does not fit in `N`.
fn checked_mul_int<N: FixedPointOperand>(self, n: N) -> Option<N> {
let lhs: I129 = self.into_inner().into();
let rhs: I129 = n.into();
let negative = lhs.negative != rhs.negative;
multiply_by_rational_with_rounding(
lhs.value,
rhs.value,
Self::DIV.unique_saturated_into(),
Rounding::from_signed(SignedRounding::Minor, negative),
)
.and_then(|value| from_i129(I129 { value, negative }))
}Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Rounding
impl Send for Rounding
impl Sync for Rounding
impl Unpin for Rounding
impl UnwindSafe for Rounding
Blanket Implementations§
source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
Consume self to return an equivalent value of
T. Read moresource§impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
Consume self to return an equivalent value of
T.