43
43
//! ```rust
44
44
//! extern crate rand;
45
45
//! extern crate num;
46
+ //!
47
+ //! # #[cfg(feature = "rand")]
46
48
//! # fn main() {
47
49
//! use num::bigint::{ToBigInt, RandBigInt};
48
50
//!
56
58
//! // Probably an even larger number.
57
59
//! println!("{}", a * b);
58
60
//! # }
61
+ //!
62
+ //! # #[cfg(not(feature = "rand"))]
63
+ //! # fn main() {
64
+ //! # }
59
65
//! ```
60
66
61
67
use Integer ;
@@ -71,6 +77,10 @@ use std::cmp::Ordering::{self, Less, Greater, Equal};
71
77
use std:: { f32, f64} ;
72
78
use std:: { u8, i64, u64} ;
73
79
80
+ // Some of the tests of non-RNG-based functionality are randomized using the
81
+ // RNG-based functionality, so the RNG-based functionality needs to be enabled
82
+ // for tests.
83
+ #[ cfg( any( feature = "rand" , test) ) ]
74
84
use rand:: Rng ;
75
85
76
86
use traits:: { ToPrimitive , FromPrimitive } ;
@@ -173,11 +183,13 @@ fn div_wide(hi: BigDigit, lo: BigDigit, divisor: BigDigit) -> (BigDigit, BigDigi
173
183
let rhs = divisor as DoubleBigDigit ;
174
184
( ( lhs / rhs) as BigDigit , ( lhs % rhs) as BigDigit )
175
185
}
186
+
176
187
/// A big unsigned integer type.
177
188
///
178
189
/// A `BigUint`-typed value `BigUint { data: vec!(a, b, c) }` represents a number
179
190
/// `(a + b * big_digit::BASE + c * big_digit::BASE^2)`.
180
- #[ derive( Clone , RustcEncodable , RustcDecodable , Debug , Hash ) ]
191
+ #[ derive( Clone , Debug , Hash ) ]
192
+ #[ cfg_attr( feature = "rustc-serialize" , derive( RustcEncodable , RustcDecodable ) ) ]
181
193
pub struct BigUint {
182
194
data : Vec < BigDigit >
183
195
}
@@ -1729,7 +1741,8 @@ fn get_radix_base(radix: u32) -> (DoubleBigDigit, usize) {
1729
1741
}
1730
1742
1731
1743
/// A Sign is a `BigInt`'s composing element.
1732
- #[ derive( PartialEq , PartialOrd , Eq , Ord , Copy , Clone , Debug , RustcEncodable , RustcDecodable , Hash ) ]
1744
+ #[ derive( PartialEq , PartialOrd , Eq , Ord , Copy , Clone , Debug , Hash ) ]
1745
+ #[ cfg_attr( feature = "rustc-serialize" , derive( RustcEncodable , RustcDecodable ) ) ]
1733
1746
pub enum Sign { Minus , NoSign , Plus }
1734
1747
1735
1748
impl Neg for Sign {
@@ -1760,7 +1773,8 @@ impl Mul<Sign> for Sign {
1760
1773
}
1761
1774
1762
1775
/// A big signed integer type.
1763
- #[ derive( Clone , RustcEncodable , RustcDecodable , Debug , Hash ) ]
1776
+ #[ derive( Clone , Debug , Hash ) ]
1777
+ #[ cfg_attr( feature = "rustc-serialize" , derive( RustcEncodable , RustcDecodable ) ) ]
1764
1778
pub struct BigInt {
1765
1779
sign : Sign ,
1766
1780
data : BigUint
@@ -2387,6 +2401,7 @@ pub trait RandBigInt {
2387
2401
fn gen_bigint_range ( & mut self , lbound : & BigInt , ubound : & BigInt ) -> BigInt ;
2388
2402
}
2389
2403
2404
+ #[ cfg( any( feature = "rand" , test) ) ]
2390
2405
impl < R : Rng > RandBigInt for R {
2391
2406
fn gen_biguint ( & mut self , bit_size : usize ) -> BigUint {
2392
2407
let ( digits, rem) = bit_size. div_rem ( & big_digit:: BITS ) ;
0 commit comments