@@ -298,13 +298,13 @@ impl Integer for T {
298
298
* ~~~
299
299
*/
300
300
#[inline(always)]
301
- fn div(&self, other: T) -> T {
301
+ fn div(&self, other: & T) -> T {
302
302
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
303
303
// December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf)
304
304
match self.quot_rem(other) {
305
- (q, r) if (r > 0 && other < 0)
306
- || (r < 0 && other > 0) => q - 1,
307
- (q, _) => q,
305
+ (q, r) if (r > 0 && * other < 0)
306
+ || (r < 0 && * other > 0) => q - 1,
307
+ (q, _) => q,
308
308
}
309
309
}
310
310
@@ -330,32 +330,32 @@ impl Integer for T {
330
330
* ~~~
331
331
*/
332
332
#[inline(always)]
333
- fn modulo(&self, other: T) -> T {
333
+ fn modulo(&self, other: & T) -> T {
334
334
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
335
335
// December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf)
336
- match *self % other {
337
- r if (r > 0 && other < 0)
338
- || (r < 0 && other > 0) => r + other,
339
- r => r,
336
+ match *self % * other {
337
+ r if (r > 0 && * other < 0)
338
+ || (r < 0 && * other > 0) => r + * other,
339
+ r => r,
340
340
}
341
341
}
342
342
343
343
/// Calculates `div` and `modulo` simultaneously
344
344
#[inline(always)]
345
- fn div_mod(&self, other: T) -> (T,T) {
345
+ fn div_mod(&self, other: & T) -> (T,T) {
346
346
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
347
347
// December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf)
348
348
match self.quot_rem(other) {
349
- (q, r) if (r > 0 && other < 0)
350
- || (r < 0 && other > 0) => (q - 1, r + other),
351
- (q, r) => (q, r),
349
+ (q, r) if (r > 0 && * other < 0)
350
+ || (r < 0 && * other > 0) => (q - 1, r + * other),
351
+ (q, r) => (q, r),
352
352
}
353
353
}
354
354
355
355
/// Calculates `quot` (`\` ) and `rem` (`%`) simultaneously
356
356
#[inline(always)]
357
- fn quot_rem(&self, other: T) -> (T,T) {
358
- (*self / other, *self % other)
357
+ fn quot_rem(&self, other: & T) -> (T,T) {
358
+ (*self / * other, *self % * other)
359
359
}
360
360
361
361
/**
@@ -364,9 +364,9 @@ impl Integer for T {
364
364
* The result is always positive
365
365
*/
366
366
#[inline(always)]
367
- fn gcd(&self, other: T) -> T {
367
+ fn gcd(&self, other: & T) -> T {
368
368
// Use Euclid's algorithm
369
- let mut m = *self, n = other;
369
+ let mut m = *self, n = * other;
370
370
while m != 0 {
371
371
let temp = m;
372
372
m = n % temp;
@@ -379,17 +379,17 @@ impl Integer for T {
379
379
* Calculates the Lowest Common Multiple (LCM) of the number and `other`
380
380
*/
381
381
#[inline(always)]
382
- fn lcm(&self, other: T) -> T {
383
- ((*self * other) / self.gcd(other)).abs() // should not have to recaluculate abs
382
+ fn lcm(&self, other: & T) -> T {
383
+ ((*self * * other) / self.gcd(other)).abs() // should not have to recaluculate abs
384
384
}
385
385
386
386
/// Returns `true` if the number can be divided by `other` without leaving a remainder
387
387
#[inline(always)]
388
- fn divisible_by(&self, other: T) -> bool { *self % other == 0 }
388
+ fn divisible_by(&self, other: & T) -> bool { *self % * other == 0 }
389
389
390
390
/// Returns `true` if the number is divisible by `2`
391
391
#[inline(always)]
392
- fn is_even(&self) -> bool { self.divisible_by(2) }
392
+ fn is_even(&self) -> bool { self.divisible_by(& 2) }
393
393
394
394
/// Returns `true` if the number is not divisible by `2`
395
395
#[inline(always)]
@@ -562,7 +562,7 @@ mod tests {
562
562
fn test_nd_qr(nd: (T,T), qr: (T,T)) {
563
563
let (n,d) = nd;
564
564
let separate_quot_rem = (n / d, n % d);
565
- let combined_quot_rem = n.quot_rem(d);
565
+ let combined_quot_rem = n.quot_rem(& d);
566
566
567
567
assert_eq!(separate_quot_rem, qr);
568
568
assert_eq!(combined_quot_rem, qr);
@@ -586,8 +586,8 @@ mod tests {
586
586
fn test_div_mod() {
587
587
fn test_nd_dm(nd: (T,T), dm: (T,T)) {
588
588
let (n,d) = nd;
589
- let separate_div_mod = (n.div(d), n.modulo(d));
590
- let combined_div_mod = n.div_mod(d);
589
+ let separate_div_mod = (n.div(& d), n.modulo(& d));
590
+ let combined_div_mod = n.div_mod(& d);
591
591
592
592
assert_eq!(separate_div_mod, dm);
593
593
assert_eq!(combined_div_mod, dm);
@@ -609,26 +609,26 @@ mod tests {
609
609
610
610
#[test]
611
611
fn test_gcd() {
612
- assert_eq!((10 as T).gcd(2), 2 as T);
613
- assert_eq!((10 as T).gcd(3), 1 as T);
614
- assert_eq!((0 as T).gcd(3), 3 as T);
615
- assert_eq!((3 as T).gcd(3), 3 as T);
616
- assert_eq!((56 as T).gcd(42), 14 as T);
617
- assert_eq!((3 as T).gcd(-3), 3 as T);
618
- assert_eq!((-6 as T).gcd(3), 3 as T);
619
- assert_eq!((-4 as T).gcd(-2), 2 as T);
612
+ assert_eq!((10 as T).gcd(& 2), 2 as T);
613
+ assert_eq!((10 as T).gcd(& 3), 1 as T);
614
+ assert_eq!((0 as T).gcd(& 3), 3 as T);
615
+ assert_eq!((3 as T).gcd(& 3), 3 as T);
616
+ assert_eq!((56 as T).gcd(& 42), 14 as T);
617
+ assert_eq!((3 as T).gcd(& -3), 3 as T);
618
+ assert_eq!((-6 as T).gcd(& 3), 3 as T);
619
+ assert_eq!((-4 as T).gcd(& -2), 2 as T);
620
620
}
621
621
622
622
#[test]
623
623
fn test_lcm() {
624
- assert_eq!((1 as T).lcm(0), 0 as T);
625
- assert_eq!((0 as T).lcm(1), 0 as T);
626
- assert_eq!((1 as T).lcm(1), 1 as T);
627
- assert_eq!((-1 as T).lcm(1), 1 as T);
628
- assert_eq!((1 as T).lcm(-1), 1 as T);
629
- assert_eq!((-1 as T).lcm(-1), 1 as T);
630
- assert_eq!((8 as T).lcm(9), 72 as T);
631
- assert_eq!((11 as T).lcm(5), 55 as T);
624
+ assert_eq!((1 as T).lcm(& 0), 0 as T);
625
+ assert_eq!((0 as T).lcm(& 1), 0 as T);
626
+ assert_eq!((1 as T).lcm(& 1), 1 as T);
627
+ assert_eq!((-1 as T).lcm(& 1), 1 as T);
628
+ assert_eq!((1 as T).lcm(& -1), 1 as T);
629
+ assert_eq!((-1 as T).lcm(& -1), 1 as T);
630
+ assert_eq!((8 as T).lcm(& 9), 72 as T);
631
+ assert_eq!((11 as T).lcm(& 5), 55 as T);
632
632
}
633
633
634
634
#[test]
0 commit comments