Skip to content

Commit 0987428

Browse files
committed
---
yaml --- r: 57882 b: refs/heads/incoming c: 8f63f97 h: refs/heads/master v: v3
1 parent 17730ab commit 0987428

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: bf67eb2362b7d0f37012f2d6dac604c3bbacd2c6
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/incoming: c9620dc0528866bda3a0d70036af082f45c78e96
9+
refs/heads/incoming: 8f63f9789b12a69723630ae072b6ba63203ed0f6
1010
refs/heads/dist-snap: 00dbbd01c2aee72982b3e0f9511ae1d4428c3ba9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libstd/num/rational.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ impl<T: Copy + Num + Ord>
203203
}
204204
}
205205
206+
impl<T: Copy + Num + Ord>
207+
Num for Ratio<T> {}
208+
206209
/* Utils */
207210
impl<T: Copy + Num + Ord>
208211
Round for Ratio<T> {
@@ -242,6 +245,12 @@ impl<T: Copy + Num + Ord>
242245
}
243246
}
244247
248+
impl<T: Copy + Num + Ord> Fractional for Ratio<T> {
249+
#[inline]
250+
fn recip(&self) -> Ratio<T> {
251+
Ratio::new_raw(self.denom, self.numer)
252+
}
253+
}
245254
246255
/* String conversions */
247256
impl<T: ToStr> ToStr for Ratio<T> {
@@ -446,6 +455,15 @@ mod test {
446455
assert_eq!(_3_2.fract(), _1_2);
447456
}
448457
458+
#[test]
459+
fn test_recip() {
460+
assert_eq!(_1 * _1.recip(), _1);
461+
assert_eq!(_2 * _2.recip(), _1);
462+
assert_eq!(_1_2 * _1_2.recip(), _1);
463+
assert_eq!(_3_2 * _3_2.recip(), _1);
464+
assert_eq!(_neg1_2 * _neg1_2.recip(), _1);
465+
}
466+
449467
#[test]
450468
fn test_to_from_str() {
451469
fn test(r: Rational, s: ~str) {

0 commit comments

Comments
 (0)