@@ -80,6 +80,7 @@ A big unsigned integer type.
80
80
A BigUint-typed value BigUint { data: @[a, b, c] } represents a number
81
81
(a + b * BigDigit::base + c * BigDigit::base^2).
82
82
*/
83
+ #[ deriving( Clone ) ]
83
84
pub struct BigUint {
84
85
priv data : ~[ BigDigit ]
85
86
}
@@ -680,7 +681,7 @@ priv fn get_radix_base(radix: uint) -> (uint, uint) {
680
681
}
681
682
682
683
/// A Sign is a BigInt's composing element.
683
- #[ deriving( Eq ) ]
684
+ #[ deriving( Eq , Clone ) ]
684
685
pub enum Sign { Minus , Zero , Plus }
685
686
686
687
impl Ord for Sign {
@@ -726,6 +727,7 @@ impl Neg<Sign> for Sign {
726
727
}
727
728
728
729
/// A big signed integer type.
730
+ #[ deriving( Clone ) ]
729
731
pub struct BigInt {
730
732
priv sign : Sign ,
731
733
priv data : BigUint
@@ -825,8 +827,8 @@ impl Signed for BigInt {
825
827
#[ inline( always) ]
826
828
fn abs ( & self ) -> BigInt {
827
829
match self . sign {
828
- Plus | Zero => copy * self ,
829
- Minus => BigInt :: from_biguint ( Plus , copy self . data )
830
+ Plus | Zero => self . clone ( ) ,
831
+ Minus => BigInt :: from_biguint ( Plus , self . data . clone ( ) )
830
832
}
831
833
}
832
834
@@ -850,8 +852,8 @@ impl Add<BigInt, BigInt> for BigInt {
850
852
#[ inline( always) ]
851
853
fn add ( & self , other : & BigInt ) -> BigInt {
852
854
match ( self . sign , other. sign ) {
853
- ( Zero , _) => copy * other,
854
- ( _, Zero ) => copy * self ,
855
+ ( Zero , _) => other. clone ( ) ,
856
+ ( _, Zero ) => self . clone ( ) ,
855
857
( Plus , Plus ) => BigInt :: from_biguint ( Plus ,
856
858
self . data + other. data ) ,
857
859
( Plus , Minus ) => self - ( -* other) ,
@@ -866,7 +868,7 @@ impl Sub<BigInt, BigInt> for BigInt {
866
868
fn sub ( & self , other : & BigInt ) -> BigInt {
867
869
match ( self . sign , other. sign ) {
868
870
( Zero , _) => -other,
869
- ( _, Zero ) => copy * self ,
871
+ ( _, Zero ) => self . clone ( ) ,
870
872
( Plus , Plus ) => match self . data . cmp ( & other. data ) {
871
873
Less => BigInt :: from_biguint ( Minus , other. data - self . data ) ,
872
874
Greater => BigInt :: from_biguint ( Plus , self . data - other. data ) ,
@@ -913,7 +915,7 @@ impl Rem<BigInt, BigInt> for BigInt {
913
915
impl Neg < BigInt > for BigInt {
914
916
#[ inline( always) ]
915
917
fn neg ( & self ) -> BigInt {
916
- BigInt :: from_biguint ( self . sign . neg ( ) , copy self . data )
918
+ BigInt :: from_biguint ( self . sign . neg ( ) , self . data . clone ( ) )
917
919
}
918
920
}
919
921
@@ -1100,9 +1102,9 @@ pub impl BigInt {
1100
1102
1101
1103
#[cfg(test)]
1102
1104
mod biguint_tests {
1105
+ use super::*;
1103
1106
use core::num::{IntConvertible, Zero, One, FromStrRadix};
1104
1107
use core::cmp::{Less, Equal, Greater};
1105
- use super::{BigUint, BigDigit};
1106
1108
1107
1109
#[test]
1108
1110
fn test_from_slice() {
@@ -1390,10 +1392,10 @@ mod biguint_tests {
1390
1392
let c = BigUint :: from_slice ( cVec) ;
1391
1393
1392
1394
if !a. is_zero ( ) {
1393
- assert ! ( c. div_rem( & a) == ( copy b , Zero :: zero( ) ) ) ;
1395
+ assert ! ( c. div_rem( & a) == ( b . clone ( ) , Zero :: zero( ) ) ) ;
1394
1396
}
1395
1397
if !b. is_zero ( ) {
1396
- assert ! ( c. div_rem( & b) == ( copy a , Zero :: zero( ) ) ) ;
1398
+ assert ! ( c. div_rem( & b) == ( a . clone ( ) , Zero :: zero( ) ) ) ;
1397
1399
}
1398
1400
}
1399
1401
@@ -1555,7 +1557,7 @@ mod biguint_tests {
1555
1557
1556
1558
#[cfg(test)]
1557
1559
mod bigint_tests {
1558
- use super::{BigInt, BigUint, BigDigit, Sign, Minus, Zero, Plus} ;
1560
+ use super::* ;
1559
1561
use core::cmp::{Less, Equal, Greater};
1560
1562
use core::num::{IntConvertible, Zero, One, FromStrRadix};
1561
1563
0 commit comments