File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
branches/auto/src/libstd/num Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
14
14
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
15
15
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
16
16
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17
- refs/heads/auto: c9620dc0528866bda3a0d70036af082f45c78e96
17
+ refs/heads/auto: 8f63f9789b12a69723630ae072b6ba63203ed0f6
18
18
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
19
19
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
Original file line number Diff line number Diff line change @@ -203,6 +203,9 @@ impl<T: Copy + Num + Ord>
203
203
}
204
204
}
205
205
206
+ impl<T: Copy + Num + Ord>
207
+ Num for Ratio<T> {}
208
+
206
209
/* Utils */
207
210
impl<T: Copy + Num + Ord>
208
211
Round for Ratio<T> {
@@ -242,6 +245,12 @@ impl<T: Copy + Num + Ord>
242
245
}
243
246
}
244
247
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
+ }
245
254
246
255
/* String conversions */
247
256
impl<T: ToStr> ToStr for Ratio<T> {
@@ -446,6 +455,15 @@ mod test {
446
455
assert_eq!(_3_2.fract(), _1_2);
447
456
}
448
457
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
+
449
467
#[test]
450
468
fn test_to_from_str() {
451
469
fn test(r: Rational, s: ~str) {
You can’t perform that action at this time.
0 commit comments