@@ -359,7 +359,7 @@ impl Integer for BigUint {
359
359
360
360
fn div_mod_floor_inner ( a : BigUint , b : BigUint ) -> ( BigUint , BigUint ) {
361
361
let mut m = a;
362
- let mut d = Zero :: zero :: < BigUint > ( ) ;
362
+ let mut d: BigUint = Zero :: zero ( ) ;
363
363
let mut n = 1 ;
364
364
while m >= b {
365
365
let ( d0, d_unit, b_unit) = div_estimate ( & m, & b, n) ;
@@ -411,8 +411,9 @@ impl Integer for BigUint {
411
411
if shift == 0 {
412
412
return ( BigUint :: new ( d) , One :: one ( ) , ( * b) . clone ( ) ) ;
413
413
}
414
+ let one: BigUint = One :: one ( ) ;
414
415
return ( BigUint :: from_slice ( d) . shl_unit ( shift) ,
415
- One :: one :: < BigUint > ( ) . shl_unit ( shift) ,
416
+ one. shl_unit ( shift) ,
416
417
b. shl_unit ( shift) ) ;
417
418
}
418
419
}
@@ -1168,8 +1169,8 @@ mod biguint_tests {
1168
1169
#[test]
1169
1170
fn test_shl() {
1170
1171
fn check(s: &str, shift: uint, ans: &str) {
1171
- let bu = ( FromStrRadix::from_str_radix::<BigUint> (s, 16).unwrap() << shift)
1172
- .to_str_radix(16);
1172
+ let opt_biguint: Option<BigUint> = FromStrRadix::from_str_radix(s, 16);
1173
+ let bu = (opt_biguint.unwrap() << shift) .to_str_radix(16);
1173
1174
assert_eq!(bu.as_slice(), ans);
1174
1175
}
1175
1176
@@ -1206,8 +1207,9 @@ mod biguint_tests {
1206
1207
#[ test]
1207
1208
fn test_shr( ) {
1208
1209
fn check( s: & str, shift: uint, ans: & str) {
1209
- let bu = ( FromStrRadix :: from_str_radix:: < BigUint > ( s, 16 ) . unwrap( ) >> shift)
1210
- . to_str_radix( 16 ) ;
1210
+ let opt_biguint: Option < BigUint > =
1211
+ FromStrRadix :: from_str_radix( s, 16 ) ;
1212
+ let bu = ( opt_biguint. unwrap( ) >> shift) . to_str_radix( 16 ) ;
1211
1213
assert_eq ! ( bu. as_slice( ) , ans) ;
1212
1214
}
1213
1215
@@ -1445,11 +1447,18 @@ mod biguint_tests {
1445
1447
1446
1448
#[ test]
1447
1449
fn test_is_even ( ) {
1448
- assert ! ( FromStr :: from_str:: <BigUint >( "1" ) . unwrap( ) . is_odd( ) ) ;
1449
- assert ! ( FromStr :: from_str:: <BigUint >( "2" ) . unwrap( ) . is_even( ) ) ;
1450
- assert ! ( FromStr :: from_str:: <BigUint >( "1000" ) . unwrap( ) . is_even( ) ) ;
1451
- assert ! ( FromStr :: from_str:: <BigUint >( "1000000000000000000000" ) . unwrap( ) . is_even( ) ) ;
1452
- assert ! ( FromStr :: from_str:: <BigUint >( "1000000000000000000001" ) . unwrap( ) . is_odd( ) ) ;
1450
+ let one: Option < BigUint > = FromStr :: from_str ( "1" ) ;
1451
+ let two: Option < BigUint > = FromStr :: from_str ( "2" ) ;
1452
+ let thousand: Option < BigUint > = FromStr :: from_str ( "1000" ) ;
1453
+ let big: Option < BigUint > =
1454
+ FromStr :: from_str ( "1000000000000000000000" ) ;
1455
+ let bigger: Option < BigUint > =
1456
+ FromStr :: from_str ( "1000000000000000000001" ) ;
1457
+ assert ! ( one. unwrap( ) . is_odd( ) ) ;
1458
+ assert ! ( two. unwrap( ) . is_even( ) ) ;
1459
+ assert ! ( thousand. unwrap( ) . is_even( ) ) ;
1460
+ assert ! ( big. unwrap( ) . is_even( ) ) ;
1461
+ assert ! ( bigger. unwrap( ) . is_odd( ) ) ;
1453
1462
assert ! ( ( BigUint :: from_uint( 1 ) << 64 ) . is_even( ) ) ;
1454
1463
assert ! ( ( ( BigUint :: from_uint( 1 ) << 64 ) + BigUint :: from_uint( 1 ) ) . is_odd( ) ) ;
1455
1464
}
@@ -1534,15 +1543,19 @@ mod biguint_tests {
1534
1543
}
1535
1544
}
1536
1545
1537
- assert_eq ! ( FromStrRadix :: from_str_radix:: <BigUint >( "Z" , 10 ) , None ) ;
1538
- assert_eq ! ( FromStrRadix :: from_str_radix:: <BigUint >( "_" , 2 ) , None ) ;
1539
- assert_eq ! ( FromStrRadix :: from_str_radix:: <BigUint >( "-1" , 10 ) , None ) ;
1546
+ let zed: Option < BigUint > = FromStrRadix :: from_str_radix ( "Z" , 10 ) ;
1547
+ assert_eq ! ( zed, None ) ;
1548
+ let blank: Option < BigUint > = FromStrRadix :: from_str_radix ( "_" , 2 ) ;
1549
+ assert_eq ! ( blank, None ) ;
1550
+ let minus_one: Option < BigUint > = FromStrRadix :: from_str_radix ( "-1" ,
1551
+ 10 ) ;
1552
+ assert_eq ! ( minus_one, None ) ;
1540
1553
}
1541
1554
1542
1555
#[ test]
1543
1556
fn test_factor ( ) {
1544
1557
fn factor ( n : uint ) -> BigUint {
1545
- let mut f= One :: one :: < BigUint > ( ) ;
1558
+ let mut f: BigUint = One :: one ( ) ;
1546
1559
for i in range ( 2 , n + 1 ) {
1547
1560
// FIXME(#6102): Assignment operator for BigInt causes ICE
1548
1561
// f *= BigUint::from_uint(i);
@@ -1939,17 +1952,24 @@ mod bigint_tests {
1939
1952
1940
1953
#[ test]
1941
1954
fn test_abs_sub ( ) {
1942
- assert_eq ! ( ( -One :: one:: <BigInt >( ) ) . abs_sub( & One :: one( ) ) , Zero :: zero( ) ) ;
1943
- assert_eq ! ( One :: one:: <BigInt >( ) . abs_sub( & One :: one( ) ) , Zero :: zero( ) ) ;
1944
- assert_eq ! ( One :: one:: <BigInt >( ) . abs_sub( & Zero :: zero( ) ) , One :: one( ) ) ;
1945
- assert_eq ! ( One :: one:: <BigInt >( ) . abs_sub( & -One :: one:: <BigInt >( ) ) ,
1946
- IntConvertible :: from_int( 2 ) ) ;
1955
+ let zero: BigInt = Zero :: zero ( ) ;
1956
+ let one: BigInt = One :: one ( ) ;
1957
+ assert_eq ! ( ( -one) . abs_sub( & one) , zero) ;
1958
+ let one: BigInt = One :: one ( ) ;
1959
+ let zero: BigInt = Zero :: zero ( ) ;
1960
+ assert_eq ! ( one. abs_sub( & one) , zero) ;
1961
+ let one: BigInt = One :: one ( ) ;
1962
+ let zero: BigInt = Zero :: zero ( ) ;
1963
+ assert_eq ! ( one. abs_sub( & zero) , one) ;
1964
+ let one: BigInt = One :: one ( ) ;
1965
+ assert_eq ! ( one. abs_sub( & -one) , IntConvertible :: from_int( 2 ) ) ;
1947
1966
}
1948
1967
1949
1968
#[ test]
1950
1969
fn test_to_str_radix ( ) {
1951
1970
fn check ( n : int , ans : & str ) {
1952
- assert ! ( ans == IntConvertible :: from_int:: <BigInt >( n) . to_str_radix( 10 ) ) ;
1971
+ let n: BigInt = IntConvertible :: from_int ( n) ;
1972
+ assert ! ( ans == n. to_str_radix( 10 ) ) ;
1953
1973
}
1954
1974
check ( 10 , "10" ) ;
1955
1975
check ( 1 , "1" ) ;
@@ -1962,7 +1982,10 @@ mod bigint_tests {
1962
1982
#[ test]
1963
1983
fn test_from_str_radix ( ) {
1964
1984
fn check ( s : & str , ans : Option < int > ) {
1965
- let ans = ans. map_move ( |n| IntConvertible :: from_int :: < BigInt > ( n) ) ;
1985
+ let ans = ans. map_move ( |n| {
1986
+ let x: BigInt = IntConvertible :: from_int ( n) ;
1987
+ x
1988
+ } ) ;
1966
1989
assert_eq ! ( FromStrRadix :: from_str_radix( s, 10 ) , ans) ;
1967
1990
}
1968
1991
check ( "10" , Some ( 10 ) ) ;
@@ -1980,7 +2003,8 @@ mod bigint_tests {
1980
2003
BigInt :: new( Minus , ~[ 1 , 1 , 1 ] ) ) ;
1981
2004
assert ! ( -BigInt :: new( Minus , ~[ 1 , 1 , 1 ] ) ==
1982
2005
BigInt :: new( Plus , ~[ 1 , 1 , 1 ] ) ) ;
1983
- assert_eq ! ( -Zero :: zero:: <BigInt >( ) , Zero :: zero:: <BigInt >( ) ) ;
2006
+ let zero: BigInt = Zero :: zero ( ) ;
2007
+ assert_eq ! ( -zero, zero) ;
1984
2008
}
1985
2009
}
1986
2010
@@ -1992,16 +2016,16 @@ mod bench {
1992
2016
use extra:: test:: BenchHarness ;
1993
2017
1994
2018
fn factorial ( n : uint ) -> BigUint {
1995
- let mut f = One :: one :: < BigUint > ( ) ;
2019
+ let mut f: BigUint = One :: one ( ) ;
1996
2020
for i in iterator:: range_inclusive ( 1 , n) {
1997
2021
f = f * BigUint :: from_uint ( i) ;
1998
2022
}
1999
2023
f
2000
2024
}
2001
2025
2002
2026
fn fib ( n : uint ) -> BigUint {
2003
- let mut f0 = Zero :: zero :: < BigUint > ( ) ;
2004
- let mut f1 = One :: one :: < BigUint > ( ) ;
2027
+ let mut f0: BigUint = Zero :: zero ( ) ;
2028
+ let mut f1: BigUint = One :: one ( ) ;
2005
2029
for _ in range ( 0 , n) {
2006
2030
let f2 = f0 + f1;
2007
2031
f0 = util:: replace ( & mut f1, f2) ;
0 commit comments