OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Testing Bigints with and without intrinsics. | 5 // Testing Bigints with and without intrinsics. |
6 // VMOptions= | 6 // VMOptions= |
7 // VMOptions=--no_intrinsify | 7 // VMOptions=--no_intrinsify |
8 | 8 |
9 library big_integer_test; | 9 library big_integer_test; |
| 10 |
10 import "package:expect/expect.dart"; | 11 import "package:expect/expect.dart"; |
11 | 12 |
12 addSubParsed(String a, String b, String sum) { | 13 addSubParsed(String a, String b, String sum) { |
13 int int_a = int.parse(a); | 14 int int_a = int.parse(a); |
14 int int_b = int.parse(b); | 15 int int_b = int.parse(b); |
15 int int_sum = int.parse(sum); | 16 int int_sum = int.parse(sum); |
16 int computed_sum = int_a + int_b; | 17 int computed_sum = int_a + int_b; |
17 Expect.equals(int_sum, computed_sum); | 18 Expect.equals(int_sum, computed_sum); |
18 String str_sum = computed_sum >= 0 ? | 19 String str_sum = computed_sum >= 0 |
19 "0x${computed_sum.toRadixString(16)}" : | 20 ? "0x${computed_sum.toRadixString(16)}" |
20 "-0x${(-computed_sum).toRadixString(16)}"; | 21 : "-0x${(-computed_sum).toRadixString(16)}"; |
21 Expect.equals(sum.toLowerCase(), str_sum); | 22 Expect.equals(sum.toLowerCase(), str_sum); |
22 int computed_difference1 = int_sum - int_a; | 23 int computed_difference1 = int_sum - int_a; |
23 Expect.equals(int_b, computed_difference1); | 24 Expect.equals(int_b, computed_difference1); |
24 String str_difference1 = computed_difference1 >= 0 ? | 25 String str_difference1 = computed_difference1 >= 0 |
25 "0x${computed_difference1.toRadixString(16)}" : | 26 ? "0x${computed_difference1.toRadixString(16)}" |
26 "-0x${(-computed_difference1).toRadixString(16)}"; | 27 : "-0x${(-computed_difference1).toRadixString(16)}"; |
27 Expect.equals(b.toLowerCase(), str_difference1); | 28 Expect.equals(b.toLowerCase(), str_difference1); |
28 int computed_difference2 = int_sum - int_b; | 29 int computed_difference2 = int_sum - int_b; |
29 Expect.equals(int_a, computed_difference2); | 30 Expect.equals(int_a, computed_difference2); |
30 String str_difference2 = computed_difference2 >= 0 ? | 31 String str_difference2 = computed_difference2 >= 0 |
31 "0x${computed_difference2.toRadixString(16)}" : | 32 ? "0x${computed_difference2.toRadixString(16)}" |
32 "-0x${(-computed_difference2).toRadixString(16)}"; | 33 : "-0x${(-computed_difference2).toRadixString(16)}"; |
33 Expect.equals(a.toLowerCase(), str_difference2); | 34 Expect.equals(a.toLowerCase(), str_difference2); |
34 } | 35 } |
35 | 36 |
36 testBigintAddSub() { | 37 testBigintAddSub() { |
37 String zero = "0x0"; | 38 String zero = "0x0"; |
38 String one = "0x1"; | 39 String one = "0x1"; |
39 String minus_one = "-0x1"; | 40 String minus_one = "-0x1"; |
40 | 41 |
41 addSubParsed(zero, zero, zero); | 42 addSubParsed(zero, zero, zero); |
42 addSubParsed(zero, one, one); | 43 addSubParsed(zero, one, one); |
43 addSubParsed(one, zero, one); | 44 addSubParsed(one, zero, one); |
44 addSubParsed(one, one, "0x2"); | 45 addSubParsed(one, one, "0x2"); |
45 addSubParsed(minus_one, minus_one, "-0x2"); | 46 addSubParsed(minus_one, minus_one, "-0x2"); |
46 addSubParsed("0x123", zero, "0x123"); | 47 addSubParsed("0x123", zero, "0x123"); |
47 addSubParsed(zero, "0x123", "0x123"); | 48 addSubParsed(zero, "0x123", "0x123"); |
48 addSubParsed("0x123", one, "0x124"); | 49 addSubParsed("0x123", one, "0x124"); |
49 addSubParsed(one, "0x123", "0x124"); | 50 addSubParsed(one, "0x123", "0x124"); |
50 addSubParsed("0xFFFFFFF", one, // 28 bit overflow. | 51 addSubParsed( |
51 "0x10000000"); | 52 "0xFFFFFFF", |
52 addSubParsed("0xFFFFFFFF", one, // 32 bit overflow. | 53 one, // 28 bit overflow. |
53 "0x100000000"); | 54 "0x10000000"); |
54 addSubParsed("0xFFFFFFFFFFFFFF", one, // 56 bit overflow. | 55 addSubParsed( |
55 "0x100000000000000"); | 56 "0xFFFFFFFF", |
56 addSubParsed("0xFFFFFFFFFFFFFFFF", one, // 64 bit overflow. | 57 one, // 32 bit overflow. |
57 "0x10000000000000000"); | 58 "0x100000000"); |
58 addSubParsed("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", // 128 bit. | 59 addSubParsed( |
59 one, | 60 "0xFFFFFFFFFFFFFF", |
60 "0x100000000000000000000000000000000"); | 61 one, // 56 bit overflow. |
61 addSubParsed("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | 62 "0x100000000000000"); |
62 one, | 63 addSubParsed( |
63 "0x10000000000000000000000000000000000000000000"); | 64 "0xFFFFFFFFFFFFFFFF", |
64 addSubParsed("0x8000000", // 28 bit overflow. | 65 one, // 64 bit overflow. |
65 "0x8000000", | 66 "0x10000000000000000"); |
66 "0x10000000"); | 67 addSubParsed( |
67 addSubParsed("0x80000000", // 32 bit overflow. | 68 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", // 128 bit. |
68 "0x80000000", | 69 one, |
69 "0x100000000"); | 70 "0x100000000000000000000000000000000"); |
70 addSubParsed("0x80000000000000", // 56 bit overflow. | 71 addSubParsed("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", one, |
71 "0x80000000000000", | 72 "0x10000000000000000000000000000000000000000000"); |
72 "0x100000000000000"); | 73 addSubParsed( |
73 addSubParsed("0x8000000000000000", // 64 bit overflow. | 74 "0x8000000", // 28 bit overflow. |
74 "0x8000000000000000", | 75 "0x8000000", |
75 "0x10000000000000000"); | 76 "0x10000000"); |
76 addSubParsed("0x80000000000000000000000000000000", // 128 bit. | 77 addSubParsed( |
77 "0x80000000000000000000000000000000", | 78 "0x80000000", // 32 bit overflow. |
78 "0x100000000000000000000000000000000"); | 79 "0x80000000", |
79 addSubParsed("0x8000000000000000000000000000000000000000000", | 80 "0x100000000"); |
80 "0x8000000000000000000000000000000000000000000", | 81 addSubParsed( |
81 "0x10000000000000000000000000000000000000000000"); | 82 "0x80000000000000", // 56 bit overflow. |
| 83 "0x80000000000000", |
| 84 "0x100000000000000"); |
| 85 addSubParsed( |
| 86 "0x8000000000000000", // 64 bit overflow. |
| 87 "0x8000000000000000", |
| 88 "0x10000000000000000"); |
| 89 addSubParsed( |
| 90 "0x80000000000000000000000000000000", // 128 bit. |
| 91 "0x80000000000000000000000000000000", |
| 92 "0x100000000000000000000000000000000"); |
| 93 addSubParsed( |
| 94 "0x8000000000000000000000000000000000000000000", |
| 95 "0x8000000000000000000000000000000000000000000", |
| 96 "0x10000000000000000000000000000000000000000000"); |
82 | 97 |
83 { | 98 { |
84 String a = "0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF0"; | 99 String a = "0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF0"; |
85 String sum1 = "0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF1"; | 100 String sum1 = "0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF1"; |
86 String times2 = "0x2468ACF13579BDE02468ACF121579BDE02468ACF13579BDE0"; | 101 String times2 = "0x2468ACF13579BDE02468ACF121579BDE02468ACF13579BDE0"; |
87 addSubParsed(a, zero, a); | 102 addSubParsed(a, zero, a); |
88 addSubParsed(a, one, sum1); | 103 addSubParsed(a, one, sum1); |
89 addSubParsed(a, a, times2); | 104 addSubParsed(a, a, times2); |
90 } | 105 } |
91 | 106 |
92 addSubParsed("-0x123", minus_one, "-0x124"); | 107 addSubParsed("-0x123", minus_one, "-0x124"); |
93 addSubParsed(minus_one, "-0x123", "-0x124"); | 108 addSubParsed(minus_one, "-0x123", "-0x124"); |
94 addSubParsed("-0xFFFFFFF", minus_one, // 28 bit overflow. | 109 addSubParsed( |
95 "-0x10000000"); | 110 "-0xFFFFFFF", |
96 addSubParsed("-0xFFFFFFFF", minus_one, // 32 bit overflow. | 111 minus_one, // 28 bit overflow. |
97 "-0x100000000"); | 112 "-0x10000000"); |
98 addSubParsed("-0xFFFFFFFFFFFFFF", minus_one, // 56 bit overflow. | 113 addSubParsed( |
99 "-0x100000000000000"); | 114 "-0xFFFFFFFF", |
100 addSubParsed("-0xFFFFFFFFFFFFFFFF", minus_one, // 64 bit overflow. | 115 minus_one, // 32 bit overflow. |
101 "-0x10000000000000000"); | 116 "-0x100000000"); |
102 addSubParsed("-0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", // 128 bit. | 117 addSubParsed( |
103 minus_one, | 118 "-0xFFFFFFFFFFFFFF", |
104 "-0x100000000000000000000000000000000"); | 119 minus_one, // 56 bit overflow. |
105 addSubParsed("-0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | 120 "-0x100000000000000"); |
106 minus_one, | 121 addSubParsed( |
107 "-0x10000000000000000000000000000000000000000000"); | 122 "-0xFFFFFFFFFFFFFFFF", |
108 addSubParsed("-0x8000000", // 28 bit overflow. | 123 minus_one, // 64 bit overflow. |
109 "-0x8000000", | 124 "-0x10000000000000000"); |
110 "-0x10000000"); | 125 addSubParsed( |
111 addSubParsed("-0x80000000", // 32 bit overflow. | 126 "-0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", // 128 bit. |
112 "-0x80000000", | 127 minus_one, |
113 "-0x100000000"); | 128 "-0x100000000000000000000000000000000"); |
114 addSubParsed("-0x80000000000000", // 56 bit overflow. | 129 addSubParsed("-0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", minus_one, |
115 "-0x80000000000000", | 130 "-0x10000000000000000000000000000000000000000000"); |
116 "-0x100000000000000"); | 131 addSubParsed( |
117 addSubParsed("-0x8000000000000000", // 64 bit overflow. | 132 "-0x8000000", // 28 bit overflow. |
118 "-0x8000000000000000", | 133 "-0x8000000", |
119 "-0x10000000000000000"); | 134 "-0x10000000"); |
120 addSubParsed("-0x80000000000000000000000000000000", // 128 bit. | 135 addSubParsed( |
121 "-0x80000000000000000000000000000000", | 136 "-0x80000000", // 32 bit overflow. |
122 "-0x100000000000000000000000000000000"); | 137 "-0x80000000", |
123 addSubParsed("-0x8000000000000000000000000000000000000000000", | 138 "-0x100000000"); |
124 "-0x8000000000000000000000000000000000000000000", | 139 addSubParsed( |
125 "-0x10000000000000000000000000000000000000000000"); | 140 "-0x80000000000000", // 56 bit overflow. |
| 141 "-0x80000000000000", |
| 142 "-0x100000000000000"); |
| 143 addSubParsed( |
| 144 "-0x8000000000000000", // 64 bit overflow. |
| 145 "-0x8000000000000000", |
| 146 "-0x10000000000000000"); |
| 147 addSubParsed( |
| 148 "-0x80000000000000000000000000000000", // 128 bit. |
| 149 "-0x80000000000000000000000000000000", |
| 150 "-0x100000000000000000000000000000000"); |
| 151 addSubParsed( |
| 152 "-0x8000000000000000000000000000000000000000000", |
| 153 "-0x8000000000000000000000000000000000000000000", |
| 154 "-0x10000000000000000000000000000000000000000000"); |
126 | 155 |
127 { | 156 { |
128 String a = "-0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF0"; | 157 String a = "-0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF0"; |
129 String sum1 = "-0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF1"; | 158 String sum1 = "-0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF1"; |
130 String times2 = "-0x2468ACF13579BDE02468ACF121579BDE02468ACF13579BDE0"; | 159 String times2 = "-0x2468ACF13579BDE02468ACF121579BDE02468ACF13579BDE0"; |
131 addSubParsed(a, zero, a); | 160 addSubParsed(a, zero, a); |
132 addSubParsed(a, minus_one, sum1); | 161 addSubParsed(a, minus_one, sum1); |
133 addSubParsed(a, a, times2); | 162 addSubParsed(a, a, times2); |
134 } | 163 } |
135 | 164 |
| 165 addSubParsed("0x10000000000000000000000000000000000000000000", "0xFFFF", |
| 166 "0x1000000000000000000000000000000000000000FFFF"); |
136 addSubParsed("0x10000000000000000000000000000000000000000000", | 167 addSubParsed("0x10000000000000000000000000000000000000000000", |
137 "0xFFFF", | 168 "0xFFFF00000000", "0x10000000000000000000000000000000FFFF00000000"); |
138 "0x1000000000000000000000000000000000000000FFFF"); | 169 addSubParsed("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "0x100000000", |
139 addSubParsed("0x10000000000000000000000000000000000000000000", | 170 "0x1000000000000000000000000000000000000FFFFFFFF"); |
140 "0xFFFF00000000", | 171 addSubParsed( |
141 "0x10000000000000000000000000000000FFFF00000000"); | 172 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", |
142 addSubParsed("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | 173 "0x10000000000000000000", |
143 "0x100000000", | 174 "0x10000000000000000000000000FFFFFFFFFFFFFFFFFFF"); |
144 "0x1000000000000000000000000000000000000FFFFFFFF"); | |
145 addSubParsed("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | |
146 "0x10000000000000000000", | |
147 "0x10000000000000000000000000FFFFFFFFFFFFFFFFFFF"); | |
148 | 175 |
149 addSubParsed("0xB", "-0x7", "0x4"); | 176 addSubParsed("0xB", "-0x7", "0x4"); |
150 addSubParsed("-0xB", "-0x7", "-0x12"); | 177 addSubParsed("-0xB", "-0x7", "-0x12"); |
151 addSubParsed("0xB", "0x7", "0x12"); | 178 addSubParsed("0xB", "0x7", "0x12"); |
152 addSubParsed("-0xB", "0x7", "-0x4"); | 179 addSubParsed("-0xB", "0x7", "-0x4"); |
153 addSubParsed("-0x7", "0xB", "0x4"); | 180 addSubParsed("-0x7", "0xB", "0x4"); |
154 addSubParsed("-0x7", "-0xB", "-0x12"); | 181 addSubParsed("-0x7", "-0xB", "-0x12"); |
155 addSubParsed("0x7", "0xB", "0x12"); | 182 addSubParsed("0x7", "0xB", "0x12"); |
156 addSubParsed("0x7", "-0xB", "-0x4"); | 183 addSubParsed("0x7", "-0xB", "-0x4"); |
157 } | 184 } |
158 | 185 |
159 shiftLeftParsed(String a, int amount, String result) { | 186 shiftLeftParsed(String a, int amount, String result) { |
160 int int_a = int.parse(a); | 187 int int_a = int.parse(a); |
161 int int_result = int.parse(result); | 188 int int_result = int.parse(result); |
162 int shifted = int_a << amount; | 189 int shifted = int_a << amount; |
163 Expect.equals(int_result, shifted); | 190 Expect.equals(int_result, shifted); |
164 String str_shifted = shifted >= 0 ? | 191 String str_shifted = shifted >= 0 |
165 "0x${shifted.toRadixString(16)}" : | 192 ? "0x${shifted.toRadixString(16)}" |
166 "-0x${(-shifted).toRadixString(16)}"; | 193 : "-0x${(-shifted).toRadixString(16)}"; |
167 Expect.equals(result.toLowerCase(), str_shifted); | 194 Expect.equals(result.toLowerCase(), str_shifted); |
168 int back_shifted = shifted >> amount; | 195 int back_shifted = shifted >> amount; |
169 Expect.equals(int_a, back_shifted); | 196 Expect.equals(int_a, back_shifted); |
170 String str_back_shifted = back_shifted >= 0 ? | 197 String str_back_shifted = back_shifted >= 0 |
171 "0x${back_shifted.toRadixString(16)}" : | 198 ? "0x${back_shifted.toRadixString(16)}" |
172 "-0x${(-back_shifted).toRadixString(16)}"; | 199 : "-0x${(-back_shifted).toRadixString(16)}"; |
173 Expect.equals(a.toLowerCase(), str_back_shifted); | 200 Expect.equals(a.toLowerCase(), str_back_shifted); |
174 } | 201 } |
175 | 202 |
176 testBigintLeftShift() { | 203 testBigintLeftShift() { |
177 String zero = "0x0"; | 204 String zero = "0x0"; |
178 String one = "0x1"; | 205 String one = "0x1"; |
179 String minus_one = "-0x1"; | 206 String minus_one = "-0x1"; |
180 | 207 |
181 shiftLeftParsed(zero, 0, zero); | 208 shiftLeftParsed(zero, 0, zero); |
182 shiftLeftParsed(one, 0, one); | 209 shiftLeftParsed(one, 0, one); |
(...skipping 11 matching lines...) Expand all Loading... |
194 shiftLeftParsed("0x5", 27, "0x28000000"); | 221 shiftLeftParsed("0x5", 27, "0x28000000"); |
195 shiftLeftParsed("0x5", 31, "0x280000000"); | 222 shiftLeftParsed("0x5", 31, "0x280000000"); |
196 shiftLeftParsed("0x5", 55, "0x280000000000000"); | 223 shiftLeftParsed("0x5", 55, "0x280000000000000"); |
197 shiftLeftParsed("0x5", 63, "0x28000000000000000"); | 224 shiftLeftParsed("0x5", 63, "0x28000000000000000"); |
198 shiftLeftParsed("0x5", 127, "0x280000000000000000000000000000000"); | 225 shiftLeftParsed("0x5", 127, "0x280000000000000000000000000000000"); |
199 shiftLeftParsed("0x8000001", 1, "0x10000002"); | 226 shiftLeftParsed("0x8000001", 1, "0x10000002"); |
200 shiftLeftParsed("0x80000001", 1, "0x100000002"); | 227 shiftLeftParsed("0x80000001", 1, "0x100000002"); |
201 shiftLeftParsed("0x8000000000000001", 1, "0x10000000000000002"); | 228 shiftLeftParsed("0x8000000000000001", 1, "0x10000000000000002"); |
202 shiftLeftParsed("0x8000001", 29, "0x100000020000000"); | 229 shiftLeftParsed("0x8000001", 29, "0x100000020000000"); |
203 shiftLeftParsed("0x80000001", 33, "0x10000000200000000"); | 230 shiftLeftParsed("0x80000001", 33, "0x10000000200000000"); |
204 shiftLeftParsed("0x8000000000000001", 65, | 231 shiftLeftParsed( |
205 "0x100000000000000020000000000000000"); | 232 "0x8000000000000001", 65, "0x100000000000000020000000000000000"); |
206 shiftLeftParsed(minus_one, 0, minus_one); | 233 shiftLeftParsed(minus_one, 0, minus_one); |
207 shiftLeftParsed("-0x1234", 0, "-0x1234"); | 234 shiftLeftParsed("-0x1234", 0, "-0x1234"); |
208 shiftLeftParsed(minus_one, 1, "-0x2"); | 235 shiftLeftParsed(minus_one, 1, "-0x2"); |
209 shiftLeftParsed(minus_one, 28, "-0x10000000"); | 236 shiftLeftParsed(minus_one, 28, "-0x10000000"); |
210 shiftLeftParsed(minus_one, 32, "-0x100000000"); | 237 shiftLeftParsed(minus_one, 32, "-0x100000000"); |
211 shiftLeftParsed(minus_one, 64, "-0x10000000000000000"); | 238 shiftLeftParsed(minus_one, 64, "-0x10000000000000000"); |
212 shiftLeftParsed("-0x5", 28, "-0x50000000"); | 239 shiftLeftParsed("-0x5", 28, "-0x50000000"); |
213 shiftLeftParsed("-0x5", 32, "-0x500000000"); | 240 shiftLeftParsed("-0x5", 32, "-0x500000000"); |
214 shiftLeftParsed("-0x5", 64, "-0x50000000000000000"); | 241 shiftLeftParsed("-0x5", 64, "-0x50000000000000000"); |
215 shiftLeftParsed("-0x5", 27, "-0x28000000"); | 242 shiftLeftParsed("-0x5", 27, "-0x28000000"); |
216 shiftLeftParsed("-0x5", 31, "-0x280000000"); | 243 shiftLeftParsed("-0x5", 31, "-0x280000000"); |
217 shiftLeftParsed("-0x5", 63, "-0x28000000000000000"); | 244 shiftLeftParsed("-0x5", 63, "-0x28000000000000000"); |
218 shiftLeftParsed("-0x8000001", 1, "-0x10000002"); | 245 shiftLeftParsed("-0x8000001", 1, "-0x10000002"); |
219 shiftLeftParsed("-0x80000001", 1, "-0x100000002"); | 246 shiftLeftParsed("-0x80000001", 1, "-0x100000002"); |
220 shiftLeftParsed("-0x8000000000000001", 1, "-0x10000000000000002"); | 247 shiftLeftParsed("-0x8000000000000001", 1, "-0x10000000000000002"); |
221 shiftLeftParsed("-0x8000001", 29, "-0x100000020000000"); | 248 shiftLeftParsed("-0x8000001", 29, "-0x100000020000000"); |
222 shiftLeftParsed("-0x80000001", 33, "-0x10000000200000000"); | 249 shiftLeftParsed("-0x80000001", 33, "-0x10000000200000000"); |
223 shiftLeftParsed("-0x8000000000000001", 65, | 250 shiftLeftParsed( |
224 "-0x100000000000000020000000000000000"); | 251 "-0x8000000000000001", 65, "-0x100000000000000020000000000000000"); |
225 } | 252 } |
226 | 253 |
227 shiftRightParsed(String a, int amount, String result) { | 254 shiftRightParsed(String a, int amount, String result) { |
228 int int_a = int.parse(a); | 255 int int_a = int.parse(a); |
229 int int_result = int.parse(result); | 256 int int_result = int.parse(result); |
230 int shifted = int_a >> amount; | 257 int shifted = int_a >> amount; |
231 Expect.equals(int_result, shifted); | 258 Expect.equals(int_result, shifted); |
232 String str_shifted = shifted >= 0 ? | 259 String str_shifted = shifted >= 0 |
233 "0x${shifted.toRadixString(16)}" : | 260 ? "0x${shifted.toRadixString(16)}" |
234 "-0x${(-shifted).toRadixString(16)}"; | 261 : "-0x${(-shifted).toRadixString(16)}"; |
235 Expect.equals(result.toLowerCase(), str_shifted); | 262 Expect.equals(result.toLowerCase(), str_shifted); |
236 } | 263 } |
237 | 264 |
238 testBigintRightShift() { | 265 testBigintRightShift() { |
239 String zero = "0x0"; | 266 String zero = "0x0"; |
240 String one = "0x1"; | 267 String one = "0x1"; |
241 String minus_one = "-0x1"; | 268 String minus_one = "-0x1"; |
242 | 269 |
243 shiftRightParsed(one, 1, zero); | 270 shiftRightParsed(one, 1, zero); |
244 shiftRightParsed(minus_one, 1, minus_one); | 271 shiftRightParsed(minus_one, 1, minus_one); |
(...skipping 18 matching lines...) Expand all Loading... |
263 shiftRightParsed("-0x300000000", 33, "-0x2"); | 290 shiftRightParsed("-0x300000000", 33, "-0x2"); |
264 shiftRightParsed("-0x30000000000000000", 65, "-0x2"); | 291 shiftRightParsed("-0x30000000000000000", 65, "-0x2"); |
265 } | 292 } |
266 | 293 |
267 bitAndParsed(String a, String b, String result) { | 294 bitAndParsed(String a, String b, String result) { |
268 int int_a = int.parse(a); | 295 int int_a = int.parse(a); |
269 int int_b = int.parse(b); | 296 int int_b = int.parse(b); |
270 int int_result = int.parse(result); | 297 int int_result = int.parse(result); |
271 int anded = int_a & int_b; | 298 int anded = int_a & int_b; |
272 Expect.equals(int_result, anded); | 299 Expect.equals(int_result, anded); |
273 String str_anded = anded >= 0 ? | 300 String str_anded = anded >= 0 |
274 "0x${anded.toRadixString(16)}" : | 301 ? "0x${anded.toRadixString(16)}" |
275 "-0x${(-anded).toRadixString(16)}"; | 302 : "-0x${(-anded).toRadixString(16)}"; |
276 Expect.equals(result.toLowerCase(), str_anded); | 303 Expect.equals(result.toLowerCase(), str_anded); |
277 int anded2 = int_b & int_a; | 304 int anded2 = int_b & int_a; |
278 Expect.equals(int_result, anded2); | 305 Expect.equals(int_result, anded2); |
279 String str_anded2 = anded2 >= 0 ? | 306 String str_anded2 = anded2 >= 0 |
280 "0x${anded2.toRadixString(16)}" : | 307 ? "0x${anded2.toRadixString(16)}" |
281 "-0x${(-anded2).toRadixString(16)}"; | 308 : "-0x${(-anded2).toRadixString(16)}"; |
282 Expect.equals(result.toLowerCase(), str_anded2); | 309 Expect.equals(result.toLowerCase(), str_anded2); |
283 } | 310 } |
284 | 311 |
285 testBigintBitAnd() { | 312 testBigintBitAnd() { |
286 String zero = "0x0"; | 313 String zero = "0x0"; |
287 String one = "0x1"; | 314 String one = "0x1"; |
288 String minus_one = "-0x1"; | 315 String minus_one = "-0x1"; |
289 | 316 |
290 bitAndParsed(one, zero, zero); | 317 bitAndParsed(one, zero, zero); |
291 bitAndParsed(one, one, one); | 318 bitAndParsed(one, one, one); |
292 bitAndParsed(minus_one, zero, zero); | 319 bitAndParsed(minus_one, zero, zero); |
293 bitAndParsed(minus_one, one, one); | 320 bitAndParsed(minus_one, one, one); |
294 bitAndParsed(minus_one, minus_one, minus_one); | 321 bitAndParsed(minus_one, minus_one, minus_one); |
295 bitAndParsed("0x5", "0x3", one); | 322 bitAndParsed("0x5", "0x3", one); |
296 bitAndParsed("0x5", minus_one, "0x5"); | 323 bitAndParsed("0x5", minus_one, "0x5"); |
297 bitAndParsed("0x50000000", one, zero); | 324 bitAndParsed("0x50000000", one, zero); |
298 bitAndParsed("0x50000000", minus_one, "0x50000000"); | 325 bitAndParsed("0x50000000", minus_one, "0x50000000"); |
299 bitAndParsed("0x500000000", one, zero); | 326 bitAndParsed("0x500000000", one, zero); |
300 bitAndParsed("0x500000000", minus_one, "0x500000000"); | 327 bitAndParsed("0x500000000", minus_one, "0x500000000"); |
301 bitAndParsed("0x50000000000000000", one, zero); | 328 bitAndParsed("0x50000000000000000", one, zero); |
302 bitAndParsed("0x50000000000000000", minus_one, "0x50000000000000000"); | 329 bitAndParsed("0x50000000000000000", minus_one, "0x50000000000000000"); |
303 bitAndParsed("-0x50000000", "-0x50000000", "-0x50000000"); | 330 bitAndParsed("-0x50000000", "-0x50000000", "-0x50000000"); |
304 bitAndParsed("-0x500000000", "-0x500000000", "-0x500000000"); | 331 bitAndParsed("-0x500000000", "-0x500000000", "-0x500000000"); |
305 bitAndParsed("-0x50000000000000000", | 332 bitAndParsed( |
306 "-0x50000000000000000", | 333 "-0x50000000000000000", "-0x50000000000000000", "-0x50000000000000000"); |
307 "-0x50000000000000000"); | 334 bitAndParsed("0x1234567890ABCDEF012345678", "0x876543210FEDCBA0987654321", |
308 bitAndParsed("0x1234567890ABCDEF012345678", | 335 "0x224422000A9C9A0002244220"); |
309 "0x876543210FEDCBA0987654321", | 336 bitAndParsed("-0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321", |
310 "0x224422000A9C9A0002244220"); | 337 "-0x977557799FEFCFEF997755778"); |
311 bitAndParsed("-0x1234567890ABCDEF012345678", | 338 bitAndParsed("0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321", |
312 "-0x876543210FEDCBA0987654321", | 339 "0x101014589002044F010101458"); |
313 "-0x977557799FEFCFEF997755778"); | 340 bitAndParsed( |
314 bitAndParsed("0x1234567890ABCDEF012345678", | 341 "0x1234567890ABCDEF012345678FFFFFFFFFFFFFFFFFFFFFFFFF", |
315 "-0x876543210FEDCBA0987654321", | 342 "-0x876543210FEDCBA0987654321", |
316 "0x101014589002044F010101458"); | 343 "0x1234567890ABCDEF012345678789ABCDEF012345F6789ABCDF"); |
317 bitAndParsed("0x1234567890ABCDEF012345678FFFFFFFFFFFFFFFFFFFFFFFFF", | |
318 "-0x876543210FEDCBA0987654321", | |
319 "0x1234567890ABCDEF012345678789ABCDEF012345F6789ABCDF"); | |
320 bitAndParsed("0x12345678", "0xFFFFFFF", "0x2345678"); | 344 bitAndParsed("0x12345678", "0xFFFFFFF", "0x2345678"); |
321 bitAndParsed("0x123456789", "0xFFFFFFFF", "0x23456789"); | 345 bitAndParsed("0x123456789", "0xFFFFFFFF", "0x23456789"); |
322 bitAndParsed("-0x10000000", "0xFFFFFFF", "0x0"); | 346 bitAndParsed("-0x10000000", "0xFFFFFFF", "0x0"); |
323 bitAndParsed("-0x100000000", "0xFFFFFFFF", "0x0"); | 347 bitAndParsed("-0x100000000", "0xFFFFFFFF", "0x0"); |
324 bitAndParsed("-0x10000001", "0xFFFFFFF", "0xFFFFFFF"); | 348 bitAndParsed("-0x10000001", "0xFFFFFFF", "0xFFFFFFF"); |
325 bitAndParsed("-0x100000001", "0xFFFFFFFF", "0xFFFFFFFF"); | 349 bitAndParsed("-0x100000001", "0xFFFFFFFF", "0xFFFFFFFF"); |
326 bitAndParsed("-0x10000001", "0x3FFFFFFF", "0x2FFFFFFF"); | 350 bitAndParsed("-0x10000001", "0x3FFFFFFF", "0x2FFFFFFF"); |
327 bitAndParsed("-0x100000001", "0x3FFFFFFFF", "0x2FFFFFFFF"); | 351 bitAndParsed("-0x100000001", "0x3FFFFFFFF", "0x2FFFFFFFF"); |
328 bitAndParsed("-0x10000000000000001", | 352 bitAndParsed( |
329 "0x3FFFFFFFFFFFFFFFF", | 353 "-0x10000000000000001", "0x3FFFFFFFFFFFFFFFF", "0x2FFFFFFFFFFFFFFFF"); |
330 "0x2FFFFFFFFFFFFFFFF"); | |
331 bitAndParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "0x0"); | 354 bitAndParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "0x0"); |
332 bitAndParsed("-0x10000000000000000", "0xFFFFFFFFFFFFFFFF", "0x0"); | 355 bitAndParsed("-0x10000000000000000", "0xFFFFFFFFFFFFFFFF", "0x0"); |
333 bitAndParsed("-0x300000000000000", | 356 bitAndParsed("-0x300000000000000", "0xFFFFFFFFFFFFFFF", "0xD00000000000000"); |
334 "0xFFFFFFFFFFFFFFF", | 357 bitAndParsed( |
335 "0xD00000000000000"); | 358 "-0x30000000000000000", "0xFFFFFFFFFFFFFFFFF", "0xD0000000000000000"); |
336 bitAndParsed("-0x30000000000000000", | |
337 "0xFFFFFFFFFFFFFFFFF", | |
338 "0xD0000000000000000"); | |
339 bitAndParsed("-0x10000000", "-0x10000000", "-0x10000000"); | 359 bitAndParsed("-0x10000000", "-0x10000000", "-0x10000000"); |
340 bitAndParsed("-0x100000000", "-0x100000000", "-0x100000000"); | 360 bitAndParsed("-0x100000000", "-0x100000000", "-0x100000000"); |
341 bitAndParsed("-0x100000000000000", | 361 bitAndParsed( |
342 "-0x100000000000000", | 362 "-0x100000000000000", "-0x100000000000000", "-0x100000000000000"); |
343 "-0x100000000000000"); | 363 bitAndParsed( |
344 bitAndParsed("-0x10000000000000000", | 364 "-0x10000000000000000", "-0x10000000000000000", "-0x10000000000000000"); |
345 "-0x10000000000000000", | |
346 "-0x10000000000000000"); | |
347 bitAndParsed("-0x3", "-0x2", "-0x4"); | 365 bitAndParsed("-0x3", "-0x2", "-0x4"); |
348 bitAndParsed("-0x10000000", "-0x10000001", "-0x20000000"); | 366 bitAndParsed("-0x10000000", "-0x10000001", "-0x20000000"); |
349 bitAndParsed("-0x100000000", "-0x100000001", "-0x200000000"); | 367 bitAndParsed("-0x100000000", "-0x100000001", "-0x200000000"); |
350 bitAndParsed("-0x100000000000000", | 368 bitAndParsed( |
351 "-0x100000000000001", | 369 "-0x100000000000000", "-0x100000000000001", "-0x200000000000000"); |
352 "-0x200000000000000"); | 370 bitAndParsed( |
353 bitAndParsed("-0x10000000000000000", | 371 "-0x10000000000000000", "-0x10000000000000001", "-0x20000000000000000"); |
354 "-0x10000000000000001", | 372 bitAndParsed( |
355 "-0x20000000000000000"); | 373 "0x123456789ABCDEF01234567890", |
356 bitAndParsed("0x123456789ABCDEF01234567890", | 374 "0x3FFFFFFF", // Max Smi for 32 bits. |
357 "0x3FFFFFFF", // Max Smi for 32 bits. | 375 "0x34567890"); |
358 "0x34567890"); | 376 bitAndParsed( |
359 bitAndParsed("0x123456789ABCDEF01274567890", | 377 "0x123456789ABCDEF01274567890", |
360 "0x3FFFFFFF", // Max Smi for 32 bits. | 378 "0x3FFFFFFF", // Max Smi for 32 bits. |
361 "0x34567890"); | 379 "0x34567890"); |
362 bitAndParsed("0x123456789ABCDEF01234567890", | 380 bitAndParsed( |
363 "0x40000000", // Max Smi for 32 bits + 1. | 381 "0x123456789ABCDEF01234567890", |
364 "0x0"); | 382 "0x40000000", // Max Smi for 32 bits + 1. |
365 bitAndParsed("0x123456789ABCDEF01274567890", | 383 "0x0"); |
366 "0x40000000", // Max Smi for 32 bits + 1. | 384 bitAndParsed( |
367 "0x40000000"); | 385 "0x123456789ABCDEF01274567890", |
368 bitAndParsed("0x123456789ABCDEF01234567890", | 386 "0x40000000", // Max Smi for 32 bits + 1. |
369 "0x3FFFFFFFFFFFFFFF", // Max Smi for 64 bits. | 387 "0x40000000"); |
370 "0x3CDEF01234567890"); | 388 bitAndParsed( |
371 bitAndParsed("0x123456789ACCDEF01234567890", | 389 "0x123456789ABCDEF01234567890", |
372 "0x4000000000000000", // Max Smi for 64 bits + 1. | 390 "0x3FFFFFFFFFFFFFFF", // Max Smi for 64 bits. |
373 "0x4000000000000000"); | 391 "0x3CDEF01234567890"); |
374 bitAndParsed("0x123456789ABCDEF01234567890", | 392 bitAndParsed( |
375 "0x4000000000000000", // Max Smi for 64 bits + 1. | 393 "0x123456789ACCDEF01234567890", |
376 "0x0"); | 394 "0x4000000000000000", // Max Smi for 64 bits + 1. |
| 395 "0x4000000000000000"); |
| 396 bitAndParsed( |
| 397 "0x123456789ABCDEF01234567890", |
| 398 "0x4000000000000000", // Max Smi for 64 bits + 1. |
| 399 "0x0"); |
377 } | 400 } |
378 | 401 |
379 bitOrParsed(String a, String b, String result) { | 402 bitOrParsed(String a, String b, String result) { |
380 int int_a = int.parse(a); | 403 int int_a = int.parse(a); |
381 int int_b = int.parse(b); | 404 int int_b = int.parse(b); |
382 int int_result = int.parse(result); | 405 int int_result = int.parse(result); |
383 int ored = int_a | int_b; | 406 int ored = int_a | int_b; |
384 Expect.equals(int_result, ored); | 407 Expect.equals(int_result, ored); |
385 String str_ored = ored >= 0 ? | 408 String str_ored = ored >= 0 |
386 "0x${ored.toRadixString(16)}" : | 409 ? "0x${ored.toRadixString(16)}" |
387 "-0x${(-ored).toRadixString(16)}"; | 410 : "-0x${(-ored).toRadixString(16)}"; |
388 Expect.equals(result.toLowerCase(), str_ored); | 411 Expect.equals(result.toLowerCase(), str_ored); |
389 int ored2 = int_b | int_a; | 412 int ored2 = int_b | int_a; |
390 Expect.equals(int_result, ored2); | 413 Expect.equals(int_result, ored2); |
391 String str_ored2 = ored2 >= 0 ? | 414 String str_ored2 = ored2 >= 0 |
392 "0x${ored2.toRadixString(16)}" : | 415 ? "0x${ored2.toRadixString(16)}" |
393 "-0x${(-ored2).toRadixString(16)}"; | 416 : "-0x${(-ored2).toRadixString(16)}"; |
394 Expect.equals(result.toLowerCase(), str_ored2); | 417 Expect.equals(result.toLowerCase(), str_ored2); |
395 } | 418 } |
396 | 419 |
397 testBigintBitOr() { | 420 testBigintBitOr() { |
398 String zero = "0x0"; | 421 String zero = "0x0"; |
399 String one = "0x1"; | 422 String one = "0x1"; |
400 String minus_one = "-0x1"; | 423 String minus_one = "-0x1"; |
401 | 424 |
402 bitOrParsed(one, zero, one); | 425 bitOrParsed(one, zero, one); |
403 bitOrParsed(one, one, one); | 426 bitOrParsed(one, one, one); |
404 bitOrParsed(minus_one, zero, minus_one); | 427 bitOrParsed(minus_one, zero, minus_one); |
405 bitOrParsed(minus_one, one, minus_one); | 428 bitOrParsed(minus_one, one, minus_one); |
406 bitOrParsed(minus_one, minus_one, minus_one); | 429 bitOrParsed(minus_one, minus_one, minus_one); |
407 bitOrParsed("-0x3", one, "-0x3"); | 430 bitOrParsed("-0x3", one, "-0x3"); |
408 bitOrParsed("0x5", "0x3", "0x7"); | 431 bitOrParsed("0x5", "0x3", "0x7"); |
409 bitOrParsed("0x5", minus_one, minus_one); | 432 bitOrParsed("0x5", minus_one, minus_one); |
410 bitOrParsed("0x5", zero, "0x5"); | 433 bitOrParsed("0x5", zero, "0x5"); |
411 bitOrParsed("0x50000000", one, "0x50000001"); | 434 bitOrParsed("0x50000000", one, "0x50000001"); |
412 bitOrParsed("0x50000000", minus_one, minus_one); | 435 bitOrParsed("0x50000000", minus_one, minus_one); |
413 bitOrParsed("0x500000000", one, "0x500000001"); | 436 bitOrParsed("0x500000000", one, "0x500000001"); |
414 bitOrParsed("0x500000000", minus_one, minus_one); | 437 bitOrParsed("0x500000000", minus_one, minus_one); |
415 bitOrParsed("0x50000000000000000", one, "0x50000000000000001"); | 438 bitOrParsed("0x50000000000000000", one, "0x50000000000000001"); |
416 bitOrParsed("0x50000000000000000", minus_one, minus_one); | 439 bitOrParsed("0x50000000000000000", minus_one, minus_one); |
417 bitOrParsed("-0x50000000", "-0x50000000", "-0x50000000"); | 440 bitOrParsed("-0x50000000", "-0x50000000", "-0x50000000"); |
418 bitOrParsed("-0x500000000", "-0x500000000", "-0x500000000"); | 441 bitOrParsed("-0x500000000", "-0x500000000", "-0x500000000"); |
419 bitOrParsed("-0x50000000000000000", | 442 bitOrParsed( |
420 "-0x50000000000000000", | 443 "-0x50000000000000000", "-0x50000000000000000", "-0x50000000000000000"); |
421 "-0x50000000000000000"); | 444 bitOrParsed("0x1234567890ABCDEF012345678", "0x876543210FEDCBA0987654321", |
422 bitOrParsed("0x1234567890ABCDEF012345678", | 445 "0x977557799FEFCFEF997755779"); |
423 "0x876543210FEDCBA0987654321", | 446 bitOrParsed("-0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321", |
424 "0x977557799FEFCFEF997755779"); | 447 "-0x224422000A9C9A0002244221"); |
425 bitOrParsed("-0x1234567890ABCDEF012345678", | 448 bitOrParsed("0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321", |
426 "-0x876543210FEDCBA0987654321", | 449 "-0x854101010F440200985410101"); |
427 "-0x224422000A9C9A0002244221"); | |
428 bitOrParsed("0x1234567890ABCDEF012345678", | |
429 "-0x876543210FEDCBA0987654321", | |
430 "-0x854101010F440200985410101"); | |
431 bitOrParsed("0x1234567890ABCDEF012345678FFFFFFFFFFFFFFFFFFFFFFFFF", | 450 bitOrParsed("0x1234567890ABCDEF012345678FFFFFFFFFFFFFFFFFFFFFFFFF", |
432 "-0x876543210FEDCBA0987654321", | 451 "-0x876543210FEDCBA0987654321", "-0x1"); |
433 "-0x1"); | |
434 bitOrParsed("0x12345678", "0xFFFFFFF", "0x1FFFFFFF"); | 452 bitOrParsed("0x12345678", "0xFFFFFFF", "0x1FFFFFFF"); |
435 bitOrParsed("0x123456789", "0xFFFFFFFF", "0x1FFFFFFFF"); | 453 bitOrParsed("0x123456789", "0xFFFFFFFF", "0x1FFFFFFFF"); |
436 bitOrParsed("-0x10000000", "0xFFFFFFF", "-0x1"); | 454 bitOrParsed("-0x10000000", "0xFFFFFFF", "-0x1"); |
437 bitOrParsed("-0x100000000", "0xFFFFFFFF", "-0x1"); | 455 bitOrParsed("-0x100000000", "0xFFFFFFFF", "-0x1"); |
438 bitOrParsed("-0x10000001", "0xFFFFFFF", "-0x10000001"); | 456 bitOrParsed("-0x10000001", "0xFFFFFFF", "-0x10000001"); |
439 bitOrParsed("-0x100000001", "0xFFFFFFFF", "-0x100000001"); | 457 bitOrParsed("-0x100000001", "0xFFFFFFFF", "-0x100000001"); |
440 bitOrParsed("-0x10000001", "0x3FFFFFFF", "-0x1"); | 458 bitOrParsed("-0x10000001", "0x3FFFFFFF", "-0x1"); |
441 bitOrParsed("-0x100000001", "0x3FFFFFFFF", "-0x1"); | 459 bitOrParsed("-0x100000001", "0x3FFFFFFFF", "-0x1"); |
442 bitOrParsed("-0x10000000000000001", "0x3FFFFFFFFFFFFFFFF", "-0x1"); | 460 bitOrParsed("-0x10000000000000001", "0x3FFFFFFFFFFFFFFFF", "-0x1"); |
443 bitOrParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "-0x1"); | 461 bitOrParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "-0x1"); |
444 bitOrParsed("-0x10000000000000000", "0xFFFFFFFFFFFFFFFF", "-0x1"); | 462 bitOrParsed("-0x10000000000000000", "0xFFFFFFFFFFFFFFFF", "-0x1"); |
445 bitOrParsed("-0x300000000000000", "0xFFFFFFFFFFFFFFF", "-0x1"); | 463 bitOrParsed("-0x300000000000000", "0xFFFFFFFFFFFFFFF", "-0x1"); |
446 bitOrParsed("-0x30000000000000000", "0xFFFFFFFFFFFFFFFFF", "-0x1"); | 464 bitOrParsed("-0x30000000000000000", "0xFFFFFFFFFFFFFFFFF", "-0x1"); |
447 bitOrParsed("-0x10000000", "-0x10000000", "-0x10000000"); | 465 bitOrParsed("-0x10000000", "-0x10000000", "-0x10000000"); |
448 bitOrParsed("-0x100000000", "-0x100000000", "-0x100000000"); | 466 bitOrParsed("-0x100000000", "-0x100000000", "-0x100000000"); |
449 bitOrParsed("-0x100000000000000", | 467 bitOrParsed("-0x100000000000000", "-0x100000000000000", "-0x100000000000000"); |
450 "-0x100000000000000", | 468 bitOrParsed( |
451 "-0x100000000000000"); | 469 "-0x10000000000000000", "-0x10000000000000000", "-0x10000000000000000"); |
452 bitOrParsed("-0x10000000000000000", | |
453 "-0x10000000000000000", | |
454 "-0x10000000000000000"); | |
455 bitOrParsed("-0x10000000", "-0x10000001", "-0x1"); | 470 bitOrParsed("-0x10000000", "-0x10000001", "-0x1"); |
456 bitOrParsed("-0x100000000", "-0x100000001", "-0x1"); | 471 bitOrParsed("-0x100000000", "-0x100000001", "-0x1"); |
457 bitOrParsed("-0x100000000000000", "-0x100000000000001", "-0x1"); | 472 bitOrParsed("-0x100000000000000", "-0x100000000000001", "-0x1"); |
458 bitOrParsed("-0x10000000000000000", "-0x10000000000000001", "-0x1"); | 473 bitOrParsed("-0x10000000000000000", "-0x10000000000000001", "-0x1"); |
459 bitOrParsed("-0x10000000000000000", "-0x1", "-0x1"); | 474 bitOrParsed("-0x10000000000000000", "-0x1", "-0x1"); |
460 } | 475 } |
461 | 476 |
462 bitXorParsed(String a, String b, String result) { | 477 bitXorParsed(String a, String b, String result) { |
463 int int_a = int.parse(a); | 478 int int_a = int.parse(a); |
464 int int_b = int.parse(b); | 479 int int_b = int.parse(b); |
465 int int_result = int.parse(result); | 480 int int_result = int.parse(result); |
466 int xored = int_a ^ int_b; | 481 int xored = int_a ^ int_b; |
467 Expect.equals(int_result, xored); | 482 Expect.equals(int_result, xored); |
468 String str_xored = xored >= 0 ? | 483 String str_xored = xored >= 0 |
469 "0x${xored.toRadixString(16)}" : | 484 ? "0x${xored.toRadixString(16)}" |
470 "-0x${(-xored).toRadixString(16)}"; | 485 : "-0x${(-xored).toRadixString(16)}"; |
471 Expect.equals(result.toLowerCase(), str_xored); | 486 Expect.equals(result.toLowerCase(), str_xored); |
472 int xored2 = int_b ^ int_a; | 487 int xored2 = int_b ^ int_a; |
473 Expect.equals(int_result, xored2); | 488 Expect.equals(int_result, xored2); |
474 String str_xored2 = xored2 >= 0 ? | 489 String str_xored2 = xored2 >= 0 |
475 "0x${xored2.toRadixString(16)}" : | 490 ? "0x${xored2.toRadixString(16)}" |
476 "-0x${(-xored2).toRadixString(16)}"; | 491 : "-0x${(-xored2).toRadixString(16)}"; |
477 Expect.equals(result.toLowerCase(), str_xored2); | 492 Expect.equals(result.toLowerCase(), str_xored2); |
478 int xored3 = int_a ^ xored2; | 493 int xored3 = int_a ^ xored2; |
479 Expect.equals(int_b, xored3); | 494 Expect.equals(int_b, xored3); |
480 String str_xored3 = xored3 >= 0 ? | 495 String str_xored3 = xored3 >= 0 |
481 "0x${xored3.toRadixString(16)}" : | 496 ? "0x${xored3.toRadixString(16)}" |
482 "-0x${(-xored3).toRadixString(16)}"; | 497 : "-0x${(-xored3).toRadixString(16)}"; |
483 Expect.equals(b.toLowerCase(), str_xored3); | 498 Expect.equals(b.toLowerCase(), str_xored3); |
484 } | 499 } |
485 | 500 |
486 testBigintBitXor() { | 501 testBigintBitXor() { |
487 String zero = "0x0"; | 502 String zero = "0x0"; |
488 String one = "0x1"; | 503 String one = "0x1"; |
489 String minus_one = "-0x1"; | 504 String minus_one = "-0x1"; |
490 | 505 |
491 bitXorParsed(one, zero, one); | 506 bitXorParsed(one, zero, one); |
492 bitXorParsed(one, one, zero); | 507 bitXorParsed(one, one, zero); |
493 bitXorParsed(minus_one, zero, minus_one); | 508 bitXorParsed(minus_one, zero, minus_one); |
494 bitXorParsed(minus_one, one, "-0x2"); | 509 bitXorParsed(minus_one, one, "-0x2"); |
495 bitXorParsed(minus_one, minus_one, zero); | 510 bitXorParsed(minus_one, minus_one, zero); |
496 bitXorParsed("0x5", "0x3", "0x6"); | 511 bitXorParsed("0x5", "0x3", "0x6"); |
497 bitXorParsed("0x5", minus_one, "-0x6"); | 512 bitXorParsed("0x5", minus_one, "-0x6"); |
498 bitXorParsed("0x5", zero, "0x5"); | 513 bitXorParsed("0x5", zero, "0x5"); |
499 bitXorParsed(minus_one, "-0x8", "0x7"); | 514 bitXorParsed(minus_one, "-0x8", "0x7"); |
500 bitXorParsed("0x50000000", one, "0x50000001"); | 515 bitXorParsed("0x50000000", one, "0x50000001"); |
501 bitXorParsed("0x50000000", minus_one, "-0x50000001"); | 516 bitXorParsed("0x50000000", minus_one, "-0x50000001"); |
502 bitXorParsed("0x500000000", one, "0x500000001"); | 517 bitXorParsed("0x500000000", one, "0x500000001"); |
503 bitXorParsed("0x500000000", minus_one, "-0x500000001"); | 518 bitXorParsed("0x500000000", minus_one, "-0x500000001"); |
504 bitXorParsed("0x50000000000000000", one, "0x50000000000000001"); | 519 bitXorParsed("0x50000000000000000", one, "0x50000000000000001"); |
505 bitXorParsed("0x50000000000000000", minus_one, "-0x50000000000000001"); | 520 bitXorParsed("0x50000000000000000", minus_one, "-0x50000000000000001"); |
506 bitXorParsed("-0x50000000", "-0x50000000", zero); | 521 bitXorParsed("-0x50000000", "-0x50000000", zero); |
507 bitXorParsed("-0x500000000", "-0x500000000", zero); | 522 bitXorParsed("-0x500000000", "-0x500000000", zero); |
508 bitXorParsed("-0x50000000000000000", "-0x50000000000000000", zero); | 523 bitXorParsed("-0x50000000000000000", "-0x50000000000000000", zero); |
509 bitXorParsed("0x1234567890ABCDEF012345678", | 524 bitXorParsed("0x1234567890ABCDEF012345678", "0x876543210FEDCBA0987654321", |
510 "0x876543210FEDCBA0987654321", | 525 "0x955115599F46064F995511559"); |
511 "0x955115599F46064F995511559"); | 526 bitXorParsed("-0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321", |
512 bitXorParsed("-0x1234567890ABCDEF012345678", | 527 "0x955115599F46064F995511557"); |
513 "-0x876543210FEDCBA0987654321", | 528 bitXorParsed("0x1234567890ABCDEF012345678", "-0x876543210FEDCBA0987654321", |
514 "0x955115599F46064F995511557"); | 529 "-0x955115599F46064F995511559"); |
515 bitXorParsed("0x1234567890ABCDEF012345678", | 530 bitXorParsed( |
516 "-0x876543210FEDCBA0987654321", | 531 "0x1234567890ABCDEF012345678FFFFFFFFFFFFFFFFFFFFFFFFF", |
517 "-0x955115599F46064F995511559"); | 532 "-0x876543210FEDCBA0987654321", |
518 bitXorParsed("0x1234567890ABCDEF012345678FFFFFFFFFFFFFFFFFFFFFFFFF", | 533 "-0x1234567890ABCDEF012345678789ABCDEF012345F6789ABCE0"); |
519 "-0x876543210FEDCBA0987654321", | |
520 "-0x1234567890ABCDEF012345678789ABCDEF012345F6789ABCE0"); | |
521 bitXorParsed("0x12345678", "0xFFFFFFF", "0x1DCBA987"); | 534 bitXorParsed("0x12345678", "0xFFFFFFF", "0x1DCBA987"); |
522 bitXorParsed("0x123456789", "0xFFFFFFFF", "0x1DCBA9876"); | 535 bitXorParsed("0x123456789", "0xFFFFFFFF", "0x1DCBA9876"); |
523 bitXorParsed("-0x10000000", "0xFFFFFFF", "-0x1"); | 536 bitXorParsed("-0x10000000", "0xFFFFFFF", "-0x1"); |
524 bitXorParsed("-0x100000000", "0xFFFFFFFF", "-0x1"); | 537 bitXorParsed("-0x100000000", "0xFFFFFFFF", "-0x1"); |
525 bitXorParsed("-0x10000001", "0xFFFFFFF", "-0x20000000"); | 538 bitXorParsed("-0x10000001", "0xFFFFFFF", "-0x20000000"); |
526 bitXorParsed("-0x100000001", "0xFFFFFFFF", "-0x200000000"); | 539 bitXorParsed("-0x100000001", "0xFFFFFFFF", "-0x200000000"); |
527 bitXorParsed("-0x10000001", "0x3FFFFFFF", "-0x30000000"); | 540 bitXorParsed("-0x10000001", "0x3FFFFFFF", "-0x30000000"); |
528 bitXorParsed("-0x100000001", "0x3FFFFFFFF", "-0x300000000"); | 541 bitXorParsed("-0x100000001", "0x3FFFFFFFF", "-0x300000000"); |
529 bitXorParsed("-0x10000000000000001", | 542 bitXorParsed( |
530 "0x3FFFFFFFFFFFFFFFF", | 543 "-0x10000000000000001", "0x3FFFFFFFFFFFFFFFF", "-0x30000000000000000"); |
531 "-0x30000000000000000"); | |
532 bitXorParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "-0x1"); | 544 bitXorParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "-0x1"); |
533 bitXorParsed("-0x10000000000000000", "0xFFFFFFFFFFFFFFFF", "-0x1"); | 545 bitXorParsed("-0x10000000000000000", "0xFFFFFFFFFFFFFFFF", "-0x1"); |
534 bitXorParsed("-0x300000000000000", | 546 bitXorParsed("-0x300000000000000", "0xFFFFFFFFFFFFFFF", "-0xD00000000000001"); |
535 "0xFFFFFFFFFFFFFFF", | 547 bitXorParsed( |
536 "-0xD00000000000001"); | 548 "-0x30000000000000000", "0xFFFFFFFFFFFFFFFFF", "-0xD0000000000000001"); |
537 bitXorParsed("-0x30000000000000000", | |
538 "0xFFFFFFFFFFFFFFFFF", | |
539 "-0xD0000000000000001"); | |
540 bitXorParsed("-0x10000000", "-0x10000000", zero); | 549 bitXorParsed("-0x10000000", "-0x10000000", zero); |
541 bitXorParsed("-0x100000000", "-0x100000000", zero); | 550 bitXorParsed("-0x100000000", "-0x100000000", zero); |
542 bitXorParsed("-0x100000000000000", "-0x100000000000000", zero); | 551 bitXorParsed("-0x100000000000000", "-0x100000000000000", zero); |
543 bitXorParsed("-0x10000000000000000", "-0x10000000000000000", zero); | 552 bitXorParsed("-0x10000000000000000", "-0x10000000000000000", zero); |
544 bitXorParsed("-0x10000000", "-0x10000001", "0x1FFFFFFF"); | 553 bitXorParsed("-0x10000000", "-0x10000001", "0x1FFFFFFF"); |
545 bitXorParsed("-0x100000000", "-0x100000001", "0x1FFFFFFFF"); | 554 bitXorParsed("-0x100000000", "-0x100000001", "0x1FFFFFFFF"); |
546 bitXorParsed("-0x100000000000000", | 555 bitXorParsed("-0x100000000000000", "-0x100000000000001", "0x1FFFFFFFFFFFFFF"); |
547 "-0x100000000000001", | 556 bitXorParsed( |
548 "0x1FFFFFFFFFFFFFF"); | 557 "-0x10000000000000000", "-0x10000000000000001", "0x1FFFFFFFFFFFFFFFF"); |
549 bitXorParsed("-0x10000000000000000", | |
550 "-0x10000000000000001", | |
551 "0x1FFFFFFFFFFFFFFFF"); | |
552 } | 558 } |
553 | 559 |
554 bitNotParsed(String a, String result) { | 560 bitNotParsed(String a, String result) { |
555 int int_a = int.parse(a); | 561 int int_a = int.parse(a); |
556 int int_result = int.parse(result); | 562 int int_result = int.parse(result); |
557 int inverted = ~int_a; | 563 int inverted = ~int_a; |
558 Expect.equals(int_result, inverted); | 564 Expect.equals(int_result, inverted); |
559 String str_inverted = inverted >= 0 ? | 565 String str_inverted = inverted >= 0 |
560 "0x${inverted.toRadixString(16)}" : | 566 ? "0x${inverted.toRadixString(16)}" |
561 "-0x${(-inverted).toRadixString(16)}"; | 567 : "-0x${(-inverted).toRadixString(16)}"; |
562 Expect.equals(result.toLowerCase(), str_inverted); | 568 Expect.equals(result.toLowerCase(), str_inverted); |
563 int back = ~inverted; | 569 int back = ~inverted; |
564 Expect.equals(int_a, back); | 570 Expect.equals(int_a, back); |
565 String str_back = back >= 0 ? | 571 String str_back = back >= 0 |
566 "0x${back.toRadixString(16)}" : | 572 ? "0x${back.toRadixString(16)}" |
567 "-0x${(-back).toRadixString(16)}"; | 573 : "-0x${(-back).toRadixString(16)}"; |
568 Expect.equals(a.toLowerCase(), str_back); | 574 Expect.equals(a.toLowerCase(), str_back); |
569 } | 575 } |
570 | 576 |
571 testBigintBitNot() { | 577 testBigintBitNot() { |
572 String zero = "0x0"; | 578 String zero = "0x0"; |
573 String one = "0x1"; | 579 String one = "0x1"; |
574 String minus_one = "-0x1"; | 580 String minus_one = "-0x1"; |
575 | 581 |
576 bitNotParsed(zero, minus_one); | 582 bitNotParsed(zero, minus_one); |
577 bitNotParsed(one, "-0x2"); | 583 bitNotParsed(one, "-0x2"); |
578 bitNotParsed("0x5", "-0x6"); | 584 bitNotParsed("0x5", "-0x6"); |
579 bitNotParsed("0x50000000", "-0x50000001"); | 585 bitNotParsed("0x50000000", "-0x50000001"); |
580 bitNotParsed("0xFFFFFFF", "-0x10000000"); | 586 bitNotParsed("0xFFFFFFF", "-0x10000000"); |
581 bitNotParsed("0xFFFFFFFF", "-0x100000000"); | 587 bitNotParsed("0xFFFFFFFF", "-0x100000000"); |
582 bitNotParsed("0xFFFFFFFFFFFFFF", "-0x100000000000000"); | 588 bitNotParsed("0xFFFFFFFFFFFFFF", "-0x100000000000000"); |
583 bitNotParsed("0xFFFFFFFFFFFFFFFF", "-0x10000000000000000"); | 589 bitNotParsed("0xFFFFFFFFFFFFFFFF", "-0x10000000000000000"); |
584 bitNotParsed("0x1234567890ABCDEF012345678", | 590 bitNotParsed("0x1234567890ABCDEF012345678", "-0x1234567890ABCDEF012345679"); |
585 "-0x1234567890ABCDEF012345679"); | |
586 } | 591 } |
587 | 592 |
588 main() { | 593 main() { |
589 testBigintAddSub(); | 594 testBigintAddSub(); |
590 testBigintLeftShift(); | 595 testBigintLeftShift(); |
591 testBigintRightShift(); | 596 testBigintRightShift(); |
592 testBigintBitAnd(); | 597 testBigintBitAnd(); |
593 testBigintBitOr(); | 598 testBigintBitOr(); |
594 testBigintBitXor(); | 599 testBigintBitXor(); |
595 testBigintBitNot(); | 600 testBigintBitNot(); |
596 } | 601 } |
OLD | NEW |