@@ -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
}
@@ -1445,11 +1446,18 @@ mod biguint_tests {
1445
1446
1446
1447
#[ test]
1447
1448
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( ) ) ;
1449
+ let one: Option < BigUint > = FromStr :: from_str ( "1" ) ;
1450
+ let two: Option < BigUint > = FromStr :: from_str ( "2" ) ;
1451
+ let thousand: Option < BigUint > = FromStr :: from_str ( "1000" ) ;
1452
+ let big: Option < BigUint > =
1453
+ FromStr :: from_str ( "1000000000000000000000" ) ;
1454
+ let bigger: Option < BigUint > =
1455
+ FromStr :: from_str ( "1000000000000000000001" ) ;
1456
+ assert ! ( one. unwrap( ) . is_odd( ) ) ;
1457
+ assert ! ( two. unwrap( ) . is_even( ) ) ;
1458
+ assert ! ( thousand. unwrap( ) . is_even( ) ) ;
1459
+ assert ! ( big. unwrap( ) . is_even( ) ) ;
1460
+ assert ! ( bigger. unwrap( ) . is_odd( ) ) ;
1453
1461
assert ! ( ( BigUint :: from_uint( 1 ) << 64 ) . is_even( ) ) ;
1454
1462
assert ! ( ( ( BigUint :: from_uint( 1 ) << 64 ) + BigUint :: from_uint( 1 ) ) . is_odd( ) ) ;
1455
1463
}
@@ -1534,15 +1542,19 @@ mod biguint_tests {
1534
1542
}
1535
1543
}
1536
1544
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 ) ;
1545
+ let zed: Option < BigUint > = FromStrRadix :: from_str_radix ( "Z" , 10 ) ;
1546
+ assert_eq ! ( zed, None ) ;
1547
+ let blank: Option < BigUint > = FromStrRadix :: from_str_radix ( "_" , 2 ) ;
1548
+ assert_eq ! ( blank, None ) ;
1549
+ let minus_one: Option < BigUint > = FromStrRadix :: from_str_radix ( "-1" ,
1550
+ 10 ) ;
1551
+ assert_eq ! ( minus_one, None ) ;
1540
1552
}
1541
1553
1542
1554
#[ test]
1543
1555
fn test_factor ( ) {
1544
1556
fn factor ( n : uint ) -> BigUint {
1545
- let mut f= One :: one :: < BigUint > ( ) ;
1557
+ let mut f: BigUint = One :: one ( ) ;
1546
1558
for i in range ( 2 , n + 1 ) {
1547
1559
// FIXME(#6102): Assignment operator for BigInt causes ICE
1548
1560
// f *= BigUint::from_uint(i);
@@ -1939,17 +1951,24 @@ mod bigint_tests {
1939
1951
1940
1952
#[ test]
1941
1953
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 ) ) ;
1954
+ let zero: BigInt = Zero :: zero ( ) ;
1955
+ let one: BigInt = One :: one ( ) ;
1956
+ assert_eq ! ( ( -one) . abs_sub( & one) , zero) ;
1957
+ let one: BigInt = One :: one ( ) ;
1958
+ let zero: BigInt = Zero :: zero ( ) ;
1959
+ assert_eq ! ( one. abs_sub( & one) , zero) ;
1960
+ let one: BigInt = One :: one ( ) ;
1961
+ let zero: BigInt = Zero :: zero ( ) ;
1962
+ assert_eq ! ( one. abs_sub( & zero) , one) ;
1963
+ let one: BigInt = One :: one ( ) ;
1964
+ assert_eq ! ( one. abs_sub( & -one) , IntConvertible :: from_int( 2 ) ) ;
1947
1965
}
1948
1966
1949
1967
#[ test]
1950
1968
fn test_to_str_radix ( ) {
1951
1969
fn check ( n : int , ans : & str ) {
1952
- assert ! ( ans == IntConvertible :: from_int:: <BigInt >( n) . to_str_radix( 10 ) ) ;
1970
+ let n: BigInt = IntConvertible :: from_int ( n) ;
1971
+ assert ! ( ans == n. to_str_radix( 10 ) ) ;
1953
1972
}
1954
1973
check ( 10 , "10" ) ;
1955
1974
check ( 1 , "1" ) ;
@@ -1962,7 +1981,10 @@ mod bigint_tests {
1962
1981
#[ test]
1963
1982
fn test_from_str_radix ( ) {
1964
1983
fn check ( s : & str , ans : Option < int > ) {
1965
- let ans = ans. map_move ( |n| IntConvertible :: from_int :: < BigInt > ( n) ) ;
1984
+ let ans = ans. map_move ( |n| {
1985
+ let x: BigInt = IntConvertible :: from_int ( n) ;
1986
+ x
1987
+ } ) ;
1966
1988
assert_eq ! ( FromStrRadix :: from_str_radix( s, 10 ) , ans) ;
1967
1989
}
1968
1990
check ( "10" , Some ( 10 ) ) ;
@@ -1980,7 +2002,8 @@ mod bigint_tests {
1980
2002
BigInt :: new( Minus , ~[ 1 , 1 , 1 ] ) ) ;
1981
2003
assert ! ( -BigInt :: new( Minus , ~[ 1 , 1 , 1 ] ) ==
1982
2004
BigInt :: new( Plus , ~[ 1 , 1 , 1 ] ) ) ;
1983
- assert_eq ! ( -Zero :: zero:: <BigInt >( ) , Zero :: zero:: <BigInt >( ) ) ;
2005
+ let zero: BigInt = Zero :: zero ( ) ;
2006
+ assert_eq ! ( -zero, zero) ;
1984
2007
}
1985
2008
}
1986
2009
0 commit comments