10
10
11
11
/*!
12
12
13
- A Big integer (signed version: BigInt, unsigned version: BigUint).
13
+ A Big integer (signed version: ` BigInt` , unsigned version: ` BigUint` ).
14
14
15
- A BigUint is represented as an array of BigDigits .
16
- A BigInt is a combination of BigUint and Sign.
15
+ A ` BigUint` is represented as an array of `BigDigit`s .
16
+ A ` BigInt` is a combination of ` BigUint` and ` Sign` .
17
17
*/
18
18
19
19
#[ allow( missing_doc) ] ;
@@ -29,17 +29,17 @@ use std::uint;
29
29
use std:: vec;
30
30
31
31
/**
32
- A BigDigit is a BigUint's composing element.
32
+ A ` BigDigit` is a ` BigUint` 's composing element.
33
33
34
- A BigDigit is half the size of machine word size.
34
+ A ` BigDigit` is half the size of machine word size.
35
35
*/
36
36
#[ cfg( target_word_size = "32" ) ]
37
37
pub type BigDigit = u16 ;
38
38
39
39
/**
40
- A BigDigit is a BigUint's composing element.
40
+ A ` BigDigit` is a ` BigUint` 's composing element.
41
41
42
- A BigDigit is half the size of machine word size.
42
+ A ` BigDigit` is half the size of machine word size.
43
43
*/
44
44
#[ cfg( target_word_size = "64" ) ]
45
45
pub type BigDigit = u32 ;
@@ -64,13 +64,13 @@ pub mod BigDigit {
64
64
#[ inline]
65
65
fn get_lo ( n : uint ) -> BigDigit { ( n & lo_mask) as BigDigit }
66
66
67
- /// Split one machine sized unsigned integer into two BigDigits .
67
+ /// Split one machine sized unsigned integer into two `BigDigit`s .
68
68
#[ inline]
69
69
pub fn from_uint ( n : uint ) -> ( BigDigit , BigDigit ) {
70
70
( get_hi ( n) , get_lo ( n) )
71
71
}
72
72
73
- /// Join two BigDigits into one machine sized unsigned integer
73
+ /// Join two `BigDigit`s into one machine sized unsigned integer
74
74
#[ inline]
75
75
pub fn to_uint ( hi : BigDigit , lo : BigDigit ) -> uint {
76
76
( lo as uint ) | ( ( hi as uint ) << bits)
@@ -80,8 +80,8 @@ pub mod BigDigit {
80
80
/**
81
81
A big unsigned integer type.
82
82
83
- A BigUint-typed value BigUint { data: @[a, b, c] } represents a number
84
- (a + b * BigDigit::base + c * BigDigit::base^2).
83
+ A ` BigUint` -typed value ` BigUint { data: @[a, b, c] }` represents a number
84
+ ` (a + b * BigDigit::base + c * BigDigit::base^2)` .
85
85
*/
86
86
#[ deriving( Clone ) ]
87
87
pub struct BigUint {
@@ -550,7 +550,7 @@ impl ToStrRadix for BigUint {
550
550
}
551
551
552
552
impl FromStrRadix for BigUint {
553
- /// Creates and initializes an BigUint.
553
+ /// Creates and initializes a ` BigUint` .
554
554
#[ inline]
555
555
fn from_str_radix ( s : & str , radix : uint )
556
556
-> Option < BigUint > {
@@ -559,7 +559,7 @@ impl FromStrRadix for BigUint {
559
559
}
560
560
561
561
impl BigUint {
562
- /// Creates and initializes an BigUint.
562
+ /// Creates and initializes a ` BigUint` .
563
563
#[ inline]
564
564
pub fn new ( v : ~[ BigDigit ] ) -> BigUint {
565
565
// omit trailing zeros
@@ -571,7 +571,7 @@ impl BigUint {
571
571
return BigUint { data : v } ;
572
572
}
573
573
574
- /// Creates and initializes an BigUint.
574
+ /// Creates and initializes a ` BigUint` .
575
575
#[ inline]
576
576
pub fn from_uint ( n : uint ) -> BigUint {
577
577
match BigDigit :: from_uint ( n) {
@@ -581,13 +581,13 @@ impl BigUint {
581
581
}
582
582
}
583
583
584
- /// Creates and initializes an BigUint.
584
+ /// Creates and initializes a ` BigUint` .
585
585
#[ inline]
586
586
pub fn from_slice ( slice : & [ BigDigit ] ) -> BigUint {
587
587
return BigUint :: new ( slice. to_owned ( ) ) ;
588
588
}
589
589
590
- /// Creates and initializes an BigUint.
590
+ /// Creates and initializes a ` BigUint` .
591
591
pub fn parse_bytes ( buf : & [ u8 ] , radix : uint )
592
592
-> Option < BigUint > {
593
593
let ( base, unit_len) = get_radix_base ( radix) ;
@@ -615,14 +615,14 @@ impl BigUint {
615
615
}
616
616
617
617
618
- /// Converts this BigUint into a uint, failing if the conversion
618
+ /// Converts this ` BigUint` into a ` uint` , failing if the conversion
619
619
/// would overflow.
620
620
#[ inline]
621
621
pub fn to_uint ( & self ) -> uint {
622
622
self . to_uint_opt ( ) . expect ( "BigUint conversion would overflow uint" )
623
623
}
624
624
625
- /// Converts this BigUint into a uint, unless it would overflow.
625
+ /// Converts this ` BigUint` into a ` uint` , unless it would overflow.
626
626
#[ inline]
627
627
pub fn to_uint_opt ( & self ) -> Option < uint > {
628
628
match self . data . len ( ) {
@@ -633,7 +633,7 @@ impl BigUint {
633
633
}
634
634
}
635
635
636
- // Converts this BigUint into an int, unless it would overflow.
636
+ /// Converts this ` BigUint` into an ` int` , unless it would overflow.
637
637
pub fn to_int_opt ( & self ) -> Option < int > {
638
638
self . to_uint_opt ( ) . and_then ( |n| {
639
639
// If top bit of uint is set, it's too large to convert to
@@ -646,7 +646,7 @@ impl BigUint {
646
646
} )
647
647
}
648
648
649
- /// Converts this BigUint into a BigInt.
649
+ /// Converts this ` BigUint` into a ` BigInt` .
650
650
#[ inline]
651
651
pub fn to_bigint ( & self ) -> BigInt {
652
652
BigInt :: from_biguint ( Plus , self . clone ( ) )
@@ -698,7 +698,7 @@ impl BigUint {
698
698
return BigUint :: new ( shifted) ;
699
699
}
700
700
701
- /// Determines the fewest bits necessary to express the BigUint.
701
+ /// Determines the fewest bits necessary to express the ` BigUint` .
702
702
pub fn bits ( & self ) -> uint {
703
703
if self . is_zero ( ) { return 0 ; }
704
704
let zeros = self . data . last ( ) . leading_zeros ( ) ;
@@ -754,7 +754,7 @@ fn get_radix_base(radix: uint) -> (uint, uint) {
754
754
}
755
755
}
756
756
757
- /// A Sign is a BigInt's composing element.
757
+ /// A Sign is a ` BigInt` 's composing element.
758
758
#[ deriving( Eq , Clone ) ]
759
759
pub enum Sign { Minus , Zero , Plus }
760
760
@@ -1117,22 +1117,22 @@ impl FromStrRadix for BigInt {
1117
1117
}
1118
1118
1119
1119
trait RandBigInt {
1120
- /// Generate a random BigUint of the given bit size.
1120
+ /// Generate a random ` BigUint` of the given bit size.
1121
1121
fn gen_biguint(&mut self, bit_size: uint) -> BigUint;
1122
1122
1123
1123
/// Generate a random BigInt of the given bit size.
1124
1124
fn gen_bigint(&mut self, bit_size: uint) -> BigInt;
1125
1125
1126
- /// Generate a random BigUint less than the given bound. Fails
1126
+ /// Generate a random ` BigUint` less than the given bound. Fails
1127
1127
/// when the bound is zero.
1128
1128
fn gen_biguint_below(&mut self, bound: &BigUint) -> BigUint;
1129
1129
1130
- /// Generate a random BigUint within the given range. The lower
1130
+ /// Generate a random ` BigUint` within the given range. The lower
1131
1131
/// bound is inclusive; the upper bound is exclusive. Fails when
1132
1132
/// the upper bound is not greater than the lower bound.
1133
1133
fn gen_biguint_range(&mut self, lbound: &BigUint, ubound: &BigUint) -> BigUint;
1134
1134
1135
- /// Generate a random BigInt within the given range. The lower
1135
+ /// Generate a random ` BigInt` within the given range. The lower
1136
1136
/// bound is inclusive; the upper bound is exclusive. Fails when
1137
1137
/// the upper bound is not greater than the lower bound.
1138
1138
fn gen_bigint_range(&mut self, lbound: &BigInt, ubound: &BigInt) -> BigInt;
@@ -1208,7 +1208,7 @@ impl BigInt {
1208
1208
BigInt::from_biguint(sign, BigUint::new(v))
1209
1209
}
1210
1210
1211
- /// Creates and initializes an BigInt.
1211
+ /// Creates and initializes a ` BigInt` .
1212
1212
#[inline]
1213
1213
pub fn from_biguint(sign: Sign, data: BigUint) -> BigInt {
1214
1214
if sign == Zero || data.is_zero() {
@@ -1217,20 +1217,20 @@ impl BigInt {
1217
1217
return BigInt { sign: sign, data: data };
1218
1218
}
1219
1219
1220
- /// Creates and initializes an BigInt.
1220
+ /// Creates and initializes a ` BigInt` .
1221
1221
#[inline]
1222
1222
pub fn from_uint(n: uint) -> BigInt {
1223
1223
if n == 0 { return Zero::zero(); }
1224
1224
return BigInt::from_biguint(Plus, BigUint::from_uint(n));
1225
1225
}
1226
1226
1227
- /// Creates and initializes an BigInt.
1227
+ /// Creates and initializes a ` BigInt` .
1228
1228
#[inline]
1229
1229
pub fn from_slice(sign: Sign, slice: &[BigDigit]) -> BigInt {
1230
1230
BigInt::from_biguint(sign, BigUint::from_slice(slice))
1231
1231
}
1232
1232
1233
- /// Creates and initializes an BigInt.
1233
+ /// Creates and initializes a ` BigInt` .
1234
1234
pub fn parse_bytes(buf: &[u8], radix: uint)
1235
1235
-> Option<BigInt> {
1236
1236
if buf.is_empty() { return None; }
@@ -1244,14 +1244,14 @@ impl BigInt {
1244
1244
.map_move(|bu| BigInt::from_biguint(sign, bu));
1245
1245
}
1246
1246
1247
- /// Converts this BigInt into a uint, failing if the conversion
1247
+ /// Converts this ` BigInt` into a ` uint` , failing if the conversion
1248
1248
/// would overflow.
1249
1249
#[inline]
1250
1250
pub fn to_uint(&self) -> uint {
1251
1251
self.to_uint_opt().expect(" BigInt conversion would overflow uint")
1252
1252
}
1253
1253
1254
- /// Converts this BigInt into a uint, unless it would overflow.
1254
+ /// Converts this ` BigInt` into a ` uint` , unless it would overflow.
1255
1255
#[ inline]
1256
1256
pub fn to_uint_opt ( & self ) -> Option < uint > {
1257
1257
match self . sign {
@@ -1261,7 +1261,7 @@ impl BigInt {
1261
1261
}
1262
1262
}
1263
1263
1264
- /// Converts this BigInt into an int, unless it would overflow.
1264
+ /// Converts this ` BigInt` into an ` int` , unless it would overflow.
1265
1265
pub fn to_int_opt ( & self ) -> Option < int > {
1266
1266
match self . sign {
1267
1267
Plus => self . data . to_int_opt ( ) ,
@@ -1279,14 +1279,14 @@ impl BigInt {
1279
1279
}
1280
1280
}
1281
1281
1282
- /// Converts this BigInt into a BigUint, failing if BigInt is
1282
+ /// Converts this ` BigInt` into a ` BigUint` , failing if BigInt is
1283
1283
/// negative.
1284
1284
#[ inline]
1285
1285
pub fn to_biguint ( & self ) -> BigUint {
1286
1286
self . to_biguint_opt ( ) . expect ( "negative BigInt cannot convert to BigUint" )
1287
1287
}
1288
1288
1289
- /// Converts this BigInt into a BigUint, if it's not negative.
1289
+ /// Converts this ` BigInt` into a ` BigUint` , if it's not negative.
1290
1290
#[ inline]
1291
1291
pub fn to_biguint_opt ( & self ) -> Option < BigUint > {
1292
1292
match self . sign {
0 commit comments