@@ -30,7 +30,7 @@ pub type Rational64 = Ratio<i64>;
30
30
/// Alias for arbitrary precision rationals.
31
31
pub type BigRational = Ratio < BigInt > ;
32
32
33
- impl < T : Copy + Integer + Ord >
33
+ impl < T : Clone + Integer + Ord >
34
34
Ratio < T > {
35
35
/// Create a ratio representing the integer `t`.
36
36
#[ inline( always) ]
@@ -59,18 +59,23 @@ impl<T: Copy + Integer + Ord>
59
59
fn reduce(&mut self) {
60
60
let g : T = self.numer.gcd(&self.denom);
61
61
62
- self.numer /= g;
63
- self.denom /= g;
62
+ // FIXME(#6050): overloaded operators force moves with generic types
63
+ // self.numer /= g;
64
+ self.numer = self.numer / g;
65
+ // FIXME(#6050): overloaded operators force moves with generic types
66
+ // self.denom /= g;
67
+ self.denom = self.denom / g;
64
68
65
69
// keep denom positive!
66
70
if self.denom < Zero::zero() {
67
71
self.numer = -self.numer;
68
72
self.denom = -self.denom;
69
73
}
70
74
}
75
+
71
76
/// Return a `reduce`d copy of self.
72
77
fn reduced(&self) -> Ratio<T> {
73
- let mut ret = copy * self;
78
+ let mut ret = self.clone() ;
74
79
ret.reduce();
75
80
ret
76
81
}
@@ -105,7 +110,7 @@ cmp_impl!(impl TotalOrd, cmp -> cmp::Ordering)
105
110
106
111
/* Arithmetic */
107
112
// a/b * c/d = (a*c)/(b*d)
108
- impl<T: Copy + Integer + Ord>
113
+ impl<T: Clone + Integer + Ord>
109
114
Mul<Ratio<T>,Ratio<T>> for Ratio<T> {
110
115
#[inline]
111
116
fn mul(&self, rhs: &Ratio<T>) -> Ratio<T> {
@@ -114,7 +119,7 @@ impl<T: Copy + Integer + Ord>
114
119
}
115
120
116
121
// (a/b) / (c/d) = (a*d)/(b*c)
117
- impl<T: Copy + Integer + Ord>
122
+ impl<T: Clone + Integer + Ord>
118
123
Div<Ratio<T>,Ratio<T>> for Ratio<T> {
119
124
#[inline]
120
125
fn div(&self, rhs: &Ratio<T>) -> Ratio<T> {
@@ -125,7 +130,7 @@ impl<T: Copy + Integer + Ord>
125
130
// Abstracts the a/b `op` c/d = (a*d `op` b*d) / (b*d) pattern
126
131
macro_rules! arith_impl {
127
132
(impl $imp:ident, $method:ident) => {
128
- impl<T: Copy + Integer + Ord>
133
+ impl<T: Clone + Integer + Ord>
129
134
$imp<Ratio<T>,Ratio<T>> for Ratio<T> {
130
135
#[inline]
131
136
fn $method(&self, rhs: &Ratio<T>) -> Ratio<T> {
@@ -145,7 +150,7 @@ arith_impl!(impl Sub, sub)
145
150
// a/b % c/d = (a*d % b*c)/(b*d)
146
151
arith_impl!(impl Rem, rem)
147
152
148
- impl<T: Copy + Integer + Ord>
153
+ impl<T: Clone + Integer + Ord>
149
154
Neg<Ratio<T>> for Ratio<T> {
150
155
#[inline]
151
156
fn neg(&self) -> Ratio<T> {
@@ -154,7 +159,7 @@ impl<T: Copy + Integer + Ord>
154
159
}
155
160
156
161
/* Constants */
157
- impl<T: Copy + Integer + Ord>
162
+ impl<T: Clone + Integer + Ord>
158
163
Zero for Ratio<T> {
159
164
#[inline]
160
165
fn zero() -> Ratio<T> {
@@ -167,19 +172,19 @@ impl<T: Copy + Integer + Ord>
167
172
}
168
173
}
169
174
170
- impl<T: Copy + Integer + Ord>
175
+ impl<T: Clone + Integer + Ord>
171
176
One for Ratio<T> {
172
177
#[inline]
173
178
fn one() -> Ratio<T> {
174
179
Ratio::new_raw(One::one(), One::one())
175
180
}
176
181
}
177
182
178
- impl<T: Copy + Integer + Ord>
183
+ impl<T: Clone + Integer + Ord>
179
184
Num for Ratio<T> {}
180
185
181
186
/* Utils */
182
- impl<T: Copy + Integer + Ord>
187
+ impl<T: Clone + Integer + Ord>
183
188
Round for Ratio<T> {
184
189
185
190
fn floor(&self) -> Ratio<T> {
@@ -213,14 +218,14 @@ impl<T: Copy + Integer + Ord>
213
218
}
214
219
215
220
fn fract(&self) -> Ratio<T> {
216
- Ratio::new_raw(self.numer % self.denom, self.denom)
221
+ Ratio::new_raw(self.numer % self.denom, self.denom.clone() )
217
222
}
218
223
}
219
224
220
- impl<T: Copy + Integer + Ord> Fractional for Ratio<T> {
225
+ impl<T: Clone + Integer + Ord> Fractional for Ratio<T> {
221
226
#[inline]
222
227
fn recip(&self) -> Ratio<T> {
223
- Ratio::new_raw(self.denom, self.numer)
228
+ Ratio::new_raw(self.denom.clone() , self.numer.clone() )
224
229
}
225
230
}
226
231
@@ -238,7 +243,7 @@ impl<T: ToStrRadix> ToStrRadix for Ratio<T> {
238
243
}
239
244
}
240
245
241
- impl<T: FromStr + Copy + Integer + Ord>
246
+ impl<T: FromStr + Clone + Integer + Ord>
242
247
FromStr for Ratio<T> {
243
248
/// Parses `numer/denom`.
244
249
fn from_str(s: &str) -> Option<Ratio<T>> {
@@ -248,14 +253,14 @@ impl<T: FromStr + Copy + Integer + Ord>
248
253
}
249
254
});
250
255
if split.len() < 2 { return None; }
251
- do FromStr::from_str(split[0]).chain |a| {
252
- do FromStr::from_str(split[1]).chain |b| {
253
- Some(Ratio::new(a,b ))
256
+ do FromStr::from_str::<T> (split[0]).chain |a| {
257
+ do FromStr::from_str::<T> (split[1]).chain |b| {
258
+ Some(Ratio::new(a.clone(), b.clone() ))
254
259
}
255
260
}
256
261
}
257
262
}
258
- impl<T: FromStrRadix + Copy + Integer + Ord>
263
+ impl<T: FromStrRadix + Clone + Integer + Ord>
259
264
FromStrRadix for Ratio<T> {
260
265
/// Parses `numer/denom` where the numbers are in base `radix`.
261
266
fn from_str_radix(s: &str, radix: uint) -> Option<Ratio<T>> {
@@ -266,9 +271,9 @@ impl<T: FromStrRadix + Copy + Integer + Ord>
266
271
});
267
272
if split.len() < 2 { None }
268
273
else {
269
- do FromStrRadix::from_str_radix(split[0], radix).chain |a| {
270
- do FromStrRadix::from_str_radix(split[1], radix).chain |b| {
271
- Some(Ratio::new(a,b ))
274
+ do FromStrRadix::from_str_radix::<T> (split[0], radix).chain |a| {
275
+ do FromStrRadix::from_str_radix::<T> (split[1], radix).chain |b| {
276
+ Some(Ratio::new(a.clone(), b.clone() ))
272
277
}
273
278
}
274
279
}
0 commit comments