Trait fixnum::ops::RoundingMul [−][src]
pub trait RoundingMul<Rhs = Self> { type Output; type Error; fn rmul(
self,
rhs: Rhs,
mode: RoundMode
) -> Result<Self::Output, Self::Error>; fn saturating_rmul(self, rhs: Rhs, round_mode: RoundMode) -> Self::Output
where
Self: PartialOrd + Zero + Sized,
Rhs: PartialOrd + Zero,
Self::Output: Bounded, { ... } }
Associated Types
Required methods
fn rmul(self, rhs: Rhs, mode: RoundMode) -> Result<Self::Output, Self::Error>
[src]
fn rmul(self, rhs: Rhs, mode: RoundMode) -> Result<Self::Output, Self::Error>
[src]Checked rounded multiplication. Returns Err
on overflow.
Because of provided RoundMode
it’s possible to perform across the FixedPoint
values.
use fixnum::{FixedPoint, typenum::U9, ops::{Zero, RoundingMul, RoundMode::*}}; type Amount = FixedPoint<i64, U9>; let a: Amount = "0.000000001".parse()?; let b: Amount = "0.000000002".parse()?; // 1e-9 * (Ceil) 2e-9 = 1e-9 assert_eq!(a.rmul(b, Ceil)?, a); assert_eq!(b.rmul(a, Ceil)?, a); // 1e-9 * (Floor) 2e-9 = 0 assert_eq!(a.rmul(b, Floor)?, Amount::ZERO); assert_eq!(b.rmul(a, Floor)?, Amount::ZERO);
Provided methods
fn saturating_rmul(self, rhs: Rhs, round_mode: RoundMode) -> Self::Output where
Self: PartialOrd + Zero + Sized,
Rhs: PartialOrd + Zero,
Self::Output: Bounded,
[src]
fn saturating_rmul(self, rhs: Rhs, round_mode: RoundMode) -> Self::Output where
Self: PartialOrd + Zero + Sized,
Rhs: PartialOrd + Zero,
Self::Output: Bounded,
[src]Saturating rounding multiplication. Computes self * rhs
, saturating at the numeric bounds
(MIN
, MAX
) instead of overflowing.
Because of provided RoundMode
it’s possible to perform across the FixedPoint
values.
use fixnum::{FixedPoint, typenum::U9, ops::{Zero, Bounded, RoundMode::*, RoundingMul}}; type Amount = FixedPoint<i64, U9>; let a: Amount = "0.000000001".parse()?; let b: Amount = "0.000000002".parse()?; // 1e-9 * (SaturatingCeil) 2e9 = 1e-9 assert_eq!(a.saturating_rmul(b, Ceil), a); // 1e-9 * (SaturatingFloor) 2e9 = 0 assert_eq!(a.saturating_rmul(b, Floor), Amount::ZERO); // MIN * (SaturatingFloor) MIN = MAX assert_eq!(Amount::MIN.saturating_rmul(Amount::MIN, Floor), Amount::MAX); let c: Amount = "-1.000000001".parse()?; // -1.000000001 * (SaturatingCeil) MAX = MIN assert_eq!(c.saturating_rmul(Amount::MAX, Ceil), Amount::MIN);
Implementors
impl<P: Precision> RoundingMul<FixedPoint<i16, P>> for FixedPoint<i16, P>
[src]
impl<P: Precision> RoundingMul<FixedPoint<i16, P>> for FixedPoint<i16, P>
[src]type Output = FixedPoint<i16, P>
type Error = ArithmeticError
fn rmul(self, rhs: Self, mode: RoundMode) -> Result<Self, ArithmeticError>
[src]
impl<P: Precision> RoundingMul<FixedPoint<i32, P>> for FixedPoint<i32, P>
[src]
impl<P: Precision> RoundingMul<FixedPoint<i32, P>> for FixedPoint<i32, P>
[src]type Output = FixedPoint<i32, P>
type Error = ArithmeticError
fn rmul(self, rhs: Self, mode: RoundMode) -> Result<Self, ArithmeticError>
[src]
impl<P: Precision> RoundingMul<FixedPoint<i64, P>> for FixedPoint<i64, P>
[src]
impl<P: Precision> RoundingMul<FixedPoint<i64, P>> for FixedPoint<i64, P>
[src]type Output = FixedPoint<i64, P>
type Error = ArithmeticError
fn rmul(self, rhs: Self, mode: RoundMode) -> Result<Self, ArithmeticError>
[src]
impl<P: Precision> RoundingMul<FixedPoint<i128, P>> for FixedPoint<i128, P>
[src]
impl<P: Precision> RoundingMul<FixedPoint<i128, P>> for FixedPoint<i128, P>
[src]This is supported on crate feature
i128
only.