@@ -481,6 +481,7 @@ pub impl BigUint {
481
481
}
482
482
}
483
483
484
+ #[ cfg( target_arch = "x86_64" ) ]
484
485
priv pure fn get_radix_base ( radix : uint ) -> ( uint , uint ) {
485
486
assert 1 < radix && radix <= 16 ;
486
487
match radix {
@@ -503,6 +504,30 @@ priv pure fn get_radix_base(radix: uint) -> (uint, uint) {
503
504
}
504
505
}
505
506
507
+ #[ cfg( target_arch = "arm" ) ]
508
+ #[ cfg( target_arch = "x86" ) ]
509
+ priv pure fn get_radix_base ( radix : uint ) -> ( uint , uint ) {
510
+ assert 1 < radix && radix <= 16 ;
511
+ match radix {
512
+ 2 => ( 65536 , 16 ) ,
513
+ 3 => ( 59049 , 10 ) ,
514
+ 4 => ( 65536 , 8 ) ,
515
+ 5 => ( 15625 , 6 ) ,
516
+ 6 => ( 46656 , 6 ) ,
517
+ 7 => ( 16807 , 5 ) ,
518
+ 8 => ( 32768 , 5 ) ,
519
+ 9 => ( 59049 , 5 ) ,
520
+ 10 => ( 10000 , 4 ) ,
521
+ 11 => ( 14641 , 4 ) ,
522
+ 12 => ( 20736 , 4 ) ,
523
+ 13 => ( 28561 , 4 ) ,
524
+ 14 => ( 38416 , 4 ) ,
525
+ 15 => ( 50625 , 4 ) ,
526
+ 16 => ( 65536 , 4 ) ,
527
+ _ => fail
528
+ }
529
+ }
530
+
506
531
/// A Sign is a BigInt's composing element.
507
532
pub enum Sign { Minus , Zero , Plus }
508
533
@@ -853,8 +878,6 @@ mod biguint_tests {
853
878
}
854
879
855
880
#[test]
856
- #[ignore(cfg(target_arch = " x86") ) ]
857
- #[ ignore ( cfg ( target_arch = "arm" ) ) ]
858
881
fn test_shl() {
859
882
fn check(v: ~[BigDigit], shift: uint, ans: ~[BigDigit]) {
860
883
assert BigUint::new(v) << shift == BigUint::new(ans);
@@ -865,10 +888,34 @@ mod biguint_tests {
865
888
check(~[1 << (BigDigit::bits - 2)], 2, ~[0, 1]);
866
889
check(~[1 << (BigDigit::bits - 2)], 3, ~[0, 2]);
867
890
check(~[1 << (BigDigit::bits - 2)], 3 + BigDigit::bits, ~[0, 0, 2]);
868
- check ( ~[ 0x7654_3210 , 0xfedc_ba98 , 0x7654_3210 , 0xfedc_ba98 ] , 4 ,
869
- ~[ 0x6543_2100 , 0xedcb_a987 , 0x6543_210f , 0xedcb_a987 , 0xf ] ) ;
870
- check ( ~[ 0x2222_1111 , 0x4444_3333 , 0x6666_5555 , 0x8888_7777 ] , 16 ,
871
- ~[ 0x1111_0000 , 0x3333_2222 , 0x5555_4444 , 0x7777_6666 , 0x8888 ] ) ;
891
+
892
+ test_shl_bits();
893
+
894
+ #[cfg(target_arch = " x86_64") ]
895
+ fn test_shl_bits( ) {
896
+ check ( ~[ 0x7654_3210 , 0xfedc_ba98 ,
897
+ 0x7654_3210 , 0xfedc_ba98 ] , 4 ,
898
+ ~[ 0x6543_2100 , 0xedcb_a987 ,
899
+ 0x6543_210f , 0xedcb_a987 , 0xf ] ) ;
900
+ check ( ~[ 0x2222_1111 , 0x4444_3333 ,
901
+ 0x6666_5555 , 0x8888_7777 ] , 16 ,
902
+ ~[ 0x1111_0000 , 0x3333_2222 ,
903
+ 0x5555_4444 , 0x7777_6666 , 0x8888 ] ) ;
904
+ }
905
+
906
+ #[ cfg( target_arch = "arm" ) ]
907
+ #[ cfg( target_arch = "x86" ) ]
908
+ fn test_shl_bits ( ) {
909
+ check ( ~[ 0x3210 , 0x7654 , 0xba98 , 0xfedc ,
910
+ 0x3210 , 0x7654 , 0xba98 , 0xfedc ] , 4 ,
911
+ ~[ 0x2100 , 0x6543 , 0xa987 , 0xedcb ,
912
+ 0x210f , 0x6543 , 0xa987 , 0xedcb , 0xf ] ) ;
913
+ check ( ~[ 0x1111 , 0x2222 , 0x3333 , 0x4444 ,
914
+ 0x5555 , 0x6666 , 0x7777 , 0x8888 ] , 16 ,
915
+ ~[ 0x0000 , 0x1111 , 0x2222 , 0x3333 ,
916
+ 0x4444 , 0x5555 , 0x6666 , 0x7777 , 0x8888 ] ) ;
917
+ }
918
+
872
919
}
873
920
874
921
#[ test]
@@ -885,11 +932,32 @@ mod biguint_tests {
885
932
check ( ~[ 1 << 2 ] , 2 , ~[ 1 ] ) ;
886
933
check ( ~[ 1 , 2 ] , 3 , ~[ 1 << ( BigDigit :: bits - 2 ) ] ) ;
887
934
check ( ~[ 1 , 1 , 2 ] , 3 + BigDigit :: bits, ~[ 1 << ( BigDigit :: bits - 2 ) ] ) ;
888
- check ( ~[ 0x6543_2100 , 0xedcb_a987 , 0x6543_210f , 0xedcb_a987 , 0xf ] , 4 ,
889
- ~[ 0x7654_3210 , 0xfedc_ba98 , 0x7654_3210 , 0xfedc_ba98 ] ) ;
890
- check ( ~[ 0x1111_0000 , 0x3333_2222 , 0x5555_4444 , 0x7777_6666 , 0x8888 ] ,
891
- 16 ,
892
- ~[ 0x2222_1111 , 0x4444_3333 , 0x6666_5555 , 0x8888_7777 ] ) ;
935
+ test_shr_bits ( ) ;
936
+
937
+ #[ cfg( target_arch = "x86_64" ) ]
938
+ fn test_shr_bits ( ) {
939
+ check ( ~[ 0x6543_2100 , 0xedcb_a987 ,
940
+ 0x6543_210f , 0xedcb_a987 , 0xf ] , 4 ,
941
+ ~[ 0x7654_3210 , 0xfedc_ba98 ,
942
+ 0x7654_3210 , 0xfedc_ba98 ] ) ;
943
+ check ( ~[ 0x1111_0000 , 0x3333_2222 ,
944
+ 0x5555_4444 , 0x7777_6666 , 0x8888 ] , 16 ,
945
+ ~[ 0x2222_1111 , 0x4444_3333 ,
946
+ 0x6666_5555 , 0x8888_7777 ] ) ;
947
+ }
948
+
949
+ #[ cfg( target_arch = "arm" ) ]
950
+ #[ cfg( target_arch = "x86" ) ]
951
+ fn test_shr_bits ( ) {
952
+ check ( ~[ 0x2100 , 0x6543 , 0xa987 , 0xedcb ,
953
+ 0x210f , 0x6543 , 0xa987 , 0xedcb , 0xf ] , 4 ,
954
+ ~[ 0x3210 , 0x7654 , 0xba98 , 0xfedc ,
955
+ 0x3210 , 0x7654 , 0xba98 , 0xfedc ] ) ;
956
+ check ( ~[ 0x0000 , 0x1111 , 0x2222 , 0x3333 ,
957
+ 0x4444 , 0x5555 , 0x6666 , 0x7777 , 0x8888 ] , 16 ,
958
+ ~[ 0x1111 , 0x2222 , 0x3333 , 0x4444 ,
959
+ 0x5555 , 0x6666 , 0x7777 , 0x8888 ] ) ;
960
+ }
893
961
}
894
962
895
963
#[ test]
@@ -1054,6 +1122,7 @@ mod biguint_tests {
1054
1122
}
1055
1123
1056
1124
fn to_str_pairs ( ) -> ~[ ( BigUint , ~[ ( uint , ~str ) ] ) ] {
1125
+ let bits = BigDigit :: bits;
1057
1126
~[ ( Zero :: zero ( ) , ~[
1058
1127
( 2 , ~"0 ") , ( 3 , ~"0 ")
1059
1128
] ) , ( BigUint :: from_slice ( [ 0xff ] ) , ~[
@@ -1077,24 +1146,39 @@ mod biguint_tests {
1077
1146
( 4 , ~"333333 ") ,
1078
1147
( 16 , ~"fff")
1079
1148
] ) , ( BigUint :: from_slice ( [ 1 , 2 ] ) , ~[
1080
- ( 2 , ~"10 " + str:: from_chars ( vec:: from_elem ( 31 , '0' ) ) + "1" ) ,
1081
- ( 4 , ~"2 " + str:: from_chars ( vec:: from_elem ( 15 , '0' ) ) + "1" ) ,
1082
- ( 10 , ~"8589934593 ") ,
1083
- ( 16 , ~"2 " + str:: from_chars ( vec:: from_elem ( 7 , '0' ) ) + "1" )
1084
- ] ) , ( BigUint :: from_slice ( [ 1 , 2 , 3 ] ) , ~[
1085
- ( 2 , ~"11 " + str:: from_chars ( vec:: from_elem ( 30 , '0' ) ) + "10" +
1086
- str:: from_chars ( vec:: from_elem ( 31 , '0' ) ) + "1" ) ,
1087
- ( 4 , ~"3 " + str:: from_chars ( vec:: from_elem ( 15 , '0' ) ) + "2" +
1088
- str:: from_chars ( vec:: from_elem ( 15 , '0' ) ) + "1" ) ,
1089
- ( 10 , ~"55340232229718589441 ") ,
1090
- ( 16 , ~"3 " + str:: from_chars ( vec:: from_elem ( 7 , '0' ) ) + "2" +
1091
- str:: from_chars ( vec:: from_elem ( 7 , '0' ) ) + "1" )
1092
- ] ) ]
1149
+ ( 2 ,
1150
+ ~"10 " +
1151
+ str:: from_chars ( vec:: from_elem ( bits - 1 , '0' ) ) + "1" ) ,
1152
+ ( 4 ,
1153
+ ~"2 " +
1154
+ str:: from_chars ( vec:: from_elem ( bits / 2 - 1 , '0' ) ) + "1" ) ,
1155
+ ( 10 , match bits {
1156
+ 32 => ~"8589934593 ", 16 => ~"131073 ", _ => fail
1157
+ } ) ,
1158
+ ( 16 ,
1159
+ ~"2 " +
1160
+ str:: from_chars ( vec:: from_elem ( bits / 4 - 1 , '0' ) ) + "1" )
1161
+ ] ) , ( BigUint :: from_slice ( [ 1 , 2 , 3 ] ) , ~[
1162
+ ( 2 ,
1163
+ ~"11 " +
1164
+ str:: from_chars ( vec:: from_elem ( bits - 2 , '0' ) ) + "10" +
1165
+ str:: from_chars ( vec:: from_elem ( bits - 1 , '0' ) ) + "1" ) ,
1166
+ ( 4 ,
1167
+ ~"3 " +
1168
+ str:: from_chars ( vec:: from_elem ( bits / 2 - 1 , '0' ) ) + "2" +
1169
+ str:: from_chars ( vec:: from_elem ( bits / 2 - 1 , '0' ) ) + "1" ) ,
1170
+ ( 10 , match bits {
1171
+ 32 => ~"55340232229718589441 ",
1172
+ 16 => ~"12885032961 ",
1173
+ _ => fail
1174
+ } ) ,
1175
+ ( 16 , ~"3 " +
1176
+ str:: from_chars ( vec:: from_elem ( bits / 4 - 1 , '0' ) ) + "2" +
1177
+ str:: from_chars ( vec:: from_elem ( bits / 4 - 1 , '0' ) ) + "1" )
1178
+ ] ) ]
1093
1179
}
1094
1180
1095
1181
#[ test]
1096
- #[ ignore( cfg( target_arch = "x86" ) ) ]
1097
- #[ ignore( cfg( target_arch = "arm" ) ) ]
1098
1182
fn test_to_str_radix( ) {
1099
1183
for to_str_pairs( ) . each |num_pair| {
1100
1184
let & ( n, rs) = num_pair;
@@ -1106,8 +1190,6 @@ mod biguint_tests {
1106
1190
}
1107
1191
1108
1192
#[ test]
1109
- #[ ignore( cfg( target_arch = "x86" ) ) ]
1110
- #[ ignore( cfg( target_arch = "arm" ) ) ]
1111
1193
fn test_from_str_radix( ) {
1112
1194
for to_str_pairs( ) . each |num_pair| {
1113
1195
let & ( n, rs) = num_pair;
0 commit comments