diff options
| author | Michael Sullivan <sully@msully.net> | 2013-07-19 15:21:52 -0700 |
|---|---|---|
| committer | Michael Sullivan <sully@msully.net> | 2013-07-23 17:06:32 -0700 |
| commit | a0f8540c9571dadb9af542799156cc8a96263c41 (patch) | |
| tree | 7a4cac0e0f300e5973de4865f31d7c30787c0e2e /src/libextra | |
| parent | e75ec8015701d4a43ec2644dbbc4a2e051c4f515 (diff) | |
| download | rust-a0f8540c9571dadb9af542799156cc8a96263c41.tar.gz rust-a0f8540c9571dadb9af542799156cc8a96263c41.zip | |
Fix some impls such that all supertraits are actually implemented.
Diffstat (limited to 'src/libextra')
| -rw-r--r-- | src/libextra/num/bigint.rs | 5 | ||||
| -rw-r--r-- | src/libextra/num/rational.rs | 19 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index d940b6d6667..46a74457274 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -732,6 +732,11 @@ impl Ord for Sign { } } +impl TotalEq for Sign { + fn equals(&self, other: &Sign) -> bool { + *self == *other + } +} impl TotalOrd for Sign { fn cmp(&self, other: &Sign) -> Ordering { diff --git a/src/libextra/num/rational.rs b/src/libextra/num/rational.rs index 6733599d1ea..ff14009e556 100644 --- a/src/libextra/num/rational.rs +++ b/src/libextra/num/rational.rs @@ -110,6 +110,25 @@ cmp_impl!(impl TotalEq, equals) cmp_impl!(impl Ord, lt, gt, le, ge) cmp_impl!(impl TotalOrd, cmp -> cmp::Ordering) +impl<T: Clone + Integer + Ord> Orderable for Ratio<T> { + #[inline] + fn min(&self, other: &Ratio<T>) -> Ratio<T> { + if *self < *other { self.clone() } else { other.clone() } + } + + #[inline] + fn max(&self, other: &Ratio<T>) -> Ratio<T> { + if *self > *other { self.clone() } else { other.clone() } + } + + #[inline] + fn clamp(&self, mn: &Ratio<T>, mx: &Ratio<T>) -> Ratio<T> { + if *self > *mx { mx.clone()} else + if *self < *mn { mn.clone() } else { self.clone() } + } +} + + /* Arithmetic */ // a/b * c/d = (a*c)/(b*d) impl<T: Clone + Integer + Ord> |
