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
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,
fn saturating_rmul(self, rhs: Rhs, round_mode: RoundMode) -> Self::Output where
Self: PartialOrd + Zero + Sized,
Rhs: PartialOrd + Zero,
Self::Output: Bounded,
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>
This is supported on crate feature i16
only.
impl<P: Precision> RoundingMul<FixedPoint<i16, P>> for FixedPoint<i16, P>
This is supported on crate feature
i16
only.type Output = FixedPoint<i16, P>
type Error = ArithmeticError
impl<P: Precision> RoundingMul<FixedPoint<i32, P>> for FixedPoint<i32, P>
This is supported on crate feature i32
only.
impl<P: Precision> RoundingMul<FixedPoint<i32, P>> for FixedPoint<i32, P>
This is supported on crate feature
i32
only.type Output = FixedPoint<i32, P>
type Error = ArithmeticError
impl<P: Precision> RoundingMul<FixedPoint<i64, P>> for FixedPoint<i64, P>
This is supported on crate feature i64
only.
impl<P: Precision> RoundingMul<FixedPoint<i64, P>> for FixedPoint<i64, P>
This is supported on crate feature
i64
only.type Output = FixedPoint<i64, P>
type Error = ArithmeticError
impl<P: Precision> RoundingMul<FixedPoint<i128, P>> for FixedPoint<i128, P>
This is supported on crate feature i128
only.
impl<P: Precision> RoundingMul<FixedPoint<i128, P>> for FixedPoint<i128, P>
This is supported on crate feature
i128
only.