28 lines
516 B
Rust
28 lines
516 B
Rust
use crate::Proportion;
|
|
|
|
impl std::ops::Neg for Proportion {
|
|
type Output = Self;
|
|
|
|
fn neg(mut self) -> Self::Output {
|
|
self.value = 1.0 - self.value;
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::ops::Mul<f64> for Proportion {
|
|
type Output = f64;
|
|
|
|
fn mul(self, rhs: f64) -> f64 {
|
|
self.value * rhs
|
|
}
|
|
}
|
|
|
|
impl std::ops::Mul<Proportion> for usize {
|
|
type Output = usize;
|
|
|
|
fn mul(self, rhs: Proportion) -> usize {
|
|
let lhs = self as f64;
|
|
(lhs * rhs.value).round() as usize
|
|
}
|
|
}
|