diff --git a/src/rational.rs b/src/rational.rs index d7b24fd..4a4e964 100644 --- a/src/rational.rs +++ b/src/rational.rs @@ -361,7 +361,9 @@ impl Neg for Ratio type Output = Ratio; #[inline] - fn neg(self) -> Ratio { -&self } + fn neg(self) -> Ratio { + Ratio::new_raw(-self.numer, self.denom) + } } impl<'a, T> Neg for &'a Ratio @@ -371,7 +373,7 @@ impl<'a, T> Neg for &'a Ratio #[inline] fn neg(self) -> Ratio { - Ratio::new_raw(-self.numer.clone(), self.denom.clone()) + -self.clone() } } @@ -385,7 +387,7 @@ impl #[inline] fn is_zero(&self) -> bool { - *self == Zero::zero() + self.numer.is_zero() } } @@ -436,20 +438,22 @@ impl Signed for Ratio { #[inline] fn signum(&self) -> Ratio { - if *self > Zero::zero() { - One::one() + if self.is_positive() { + Self::one() } else if self.is_zero() { - Zero::zero() + Self::zero() } else { - - ::one::>() + - Self::one() } } #[inline] - fn is_positive(&self) -> bool { *self > Zero::zero() } + fn is_positive(&self) -> bool { !self.is_negative() } #[inline] - fn is_negative(&self) -> bool { *self < Zero::zero() } + fn is_negative(&self) -> bool { + self.numer.is_negative() ^ self.denom.is_negative() + } } /* String conversions */