[−][src]Trait fixnum::ops::RoundingMul
Associated Types
Loading content...Required methods
pub fn rmul(
self,
rhs: Rhs,
mode: RoundMode
) -> Result<Self::Output, Self::Error>
[src]
self,
rhs: Rhs,
mode: RoundMode
) -> Result<Self::Output, Self::Error>
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::{RoundingMul, RoundMode}}; type Amount = FixedPoint<i64, U9>; fn amount(s: &str) -> FixedPoint<i64, U9> { s.parse().unwrap() } let a = amount("0.000000001"); let b = amount("0.000000002"); // 1e-9 * (Ceil) 2e-9 = 1e-9 assert_eq!(a.rmul(b, RoundMode::Ceil)?, a); assert_eq!(b.rmul(a, RoundMode::Ceil)?, a); let zero = amount("0.0"); // 1e-9 * (Floor) 2e-9 = 0 assert_eq!(a.rmul(b, RoundMode::Floor)?, zero); assert_eq!(b.rmul(a, RoundMode::Floor)?, zero);