@@ -17,7 +17,7 @@ A BigInt is a combination of BigUint and Sign.
17
17
*/
18
18
19
19
use core:: cmp:: { Eq , Ord , TotalEq , TotalOrd , Ordering , Less , Equal , Greater } ;
20
- use core:: num:: { IntConvertible , Zero , One , ToStrRadix , FromStrRadix } ;
20
+ use core:: num:: { IntConvertible , Zero , One , ToStrRadix , FromStrRadix , Orderable } ;
21
21
22
22
/**
23
23
A BigDigit is a BigUint's composing element.
@@ -146,6 +146,24 @@ impl FromStr for BigUint {
146
146
147
147
impl Num for BigUint { }
148
148
149
+ impl Orderable for BigUint {
150
+ #[ inline( always) ]
151
+ fn min ( & self , other : & BigUint ) -> BigUint {
152
+ if self < other { self . clone ( ) } else { other. clone ( ) }
153
+ }
154
+
155
+ #[ inline( always) ]
156
+ fn max ( & self , other : & BigUint ) -> BigUint {
157
+ if self > other { self . clone ( ) } else { other. clone ( ) }
158
+ }
159
+
160
+ #[ inline( always) ]
161
+ fn clamp ( & self , mn : & BigUint , mx : & BigUint ) -> BigUint {
162
+ if self > mx { mx. clone ( ) } else
163
+ if self < mn { mn. clone ( ) } else { self . clone ( ) }
164
+ }
165
+ }
166
+
149
167
impl Shl < uint , BigUint > for BigUint {
150
168
#[ inline( always) ]
151
169
fn shl ( & self , rhs : & uint ) -> BigUint {
@@ -792,6 +810,24 @@ impl FromStr for BigInt {
792
810
793
811
impl Num for BigInt { }
794
812
813
+ impl Orderable for BigInt {
814
+ #[ inline( always) ]
815
+ fn min ( & self , other : & BigInt ) -> BigInt {
816
+ if self < other { self . clone ( ) } else { other. clone ( ) }
817
+ }
818
+
819
+ #[ inline( always) ]
820
+ fn max ( & self , other : & BigInt ) -> BigInt {
821
+ if self > other { self . clone ( ) } else { other. clone ( ) }
822
+ }
823
+
824
+ #[ inline( always) ]
825
+ fn clamp ( & self , mn : & BigInt , mx : & BigInt ) -> BigInt {
826
+ if self > mx { mx. clone ( ) } else
827
+ if self < mn { mn. clone ( ) } else { self . clone ( ) }
828
+ }
829
+ }
830
+
795
831
impl Shl < uint , BigInt > for BigInt {
796
832
#[ inline( always) ]
797
833
fn shl ( & self , rhs : & uint ) -> BigInt {
0 commit comments