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 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 x = 123456789012345678901234567891; | 216 x = 123456789012345678901234567891; |
217 e = 123456789012345678901234567899; | 217 e = 123456789012345678901234567899; |
218 m = 123456789012345678901234567890; | 218 m = 123456789012345678901234567890; |
219 Expect.equals(1, x.modPow(e, m)); | 219 Expect.equals(1, x.modPow(e, m)); |
220 x = 123456789012345678901234567891; | 220 x = 123456789012345678901234567891; |
221 e = 123456789012345678901234567890; | 221 e = 123456789012345678901234567890; |
222 m = 123456789012345678901234567899; | 222 m = 123456789012345678901234567899; |
223 Expect.equals(40128068573873018143207285483, x.modPow(e, m)); | 223 Expect.equals(40128068573873018143207285483, x.modPow(e, m)); |
224 } | 224 } |
225 | 225 |
| 226 testBigintModInverse() { |
| 227 var x, m; |
| 228 x = 1234567890; |
| 229 m = 19; |
| 230 Expect.equals(11, x.modInverse(m)); |
| 231 x = 1234567890; |
| 232 m = 1000000001; |
| 233 Expect.equals(189108911, x.modInverse(m)); |
| 234 x = 19; |
| 235 m = 1000000001; |
| 236 Expect.equals(0, x.modInverse(m)); // Not coprime. |
| 237 x = 19; |
| 238 m = 1234567890; |
| 239 Expect.equals(519818059, x.modInverse(m)); |
| 240 x = 1000000001; |
| 241 m = 1234567890; |
| 242 Expect.equals(1001100101, x.modInverse(m)); |
| 243 x = 1000000001; |
| 244 m = 19; |
| 245 Expect.equals(0, x.modInverse(m)); // Not coprime. |
| 246 x = 12345678901234567890; |
| 247 m = 19; |
| 248 Expect.equals(3, x.modInverse(m)); |
| 249 x = 12345678901234567890; |
| 250 m = 10000000000000000001; |
| 251 Expect.equals(9736746307686209582, x.modInverse(m)); |
| 252 x = 19; |
| 253 m = 10000000000000000001; |
| 254 Expect.equals(6315789473684210527, x.modInverse(m)); |
| 255 x = 19; |
| 256 m = 12345678901234567890; |
| 257 Expect.equals(0, x.modInverse(m)); // TODO(regis): Even modulus. |
| 258 x = 10000000000000000001; |
| 259 m = 12345678901234567890; |
| 260 Expect.equals(0, x.modInverse(m)); // TODO(regis): Even modulus. |
| 261 x = 10000000000000000001; |
| 262 m = 19; |
| 263 Expect.equals(7, x.modInverse(m)); |
| 264 x = 12345678901234567890; |
| 265 m = 10000000000000000001; |
| 266 Expect.equals(9736746307686209582, x.modInverse(m)); |
| 267 x = 12345678901234567890; |
| 268 m = 19; |
| 269 Expect.equals(3, x.modInverse(m)); |
| 270 x = 123456789012345678901234567890; |
| 271 m = 123456789012345678901234567899; |
| 272 Expect.equals(0, x.modInverse(m)); // Not coprime. |
| 273 x = 123456789012345678901234567890; |
| 274 m = 123456789012345678901234567891; |
| 275 Expect.equals(123456789012345678901234567890, x.modInverse(m)); |
| 276 x = 123456789012345678901234567899; |
| 277 m = 123456789012345678901234567891; |
| 278 Expect.equals(77160493132716049313271604932, x.modInverse(m)); |
| 279 x = 123456789012345678901234567899; |
| 280 m = 123456789012345678901234567890; |
| 281 Expect.equals(0, x.modInverse(m)); // TODO(regis): Even modulus. |
| 282 x = 123456789012345678901234567891; |
| 283 m = 123456789012345678901234567890; |
| 284 Expect.equals(0, x.modInverse(m)); // TODO(regis): Even modulus. |
| 285 x = 123456789012345678901234567891; |
| 286 m = 123456789012345678901234567899; |
| 287 Expect.equals(46296295879629629587962962962, x.modInverse(m)); |
| 288 } |
| 289 |
226 testBigintNegate() { | 290 testBigintNegate() { |
227 var a = 0xF000000000000000F; | 291 var a = 0xF000000000000000F; |
228 var b = ~a; // negate. | 292 var b = ~a; // negate. |
229 Expect.equals(-0xF0000000000000010, b); | 293 Expect.equals(-0xF0000000000000010, b); |
230 Expect.equals(0, a & b); | 294 Expect.equals(0, a & b); |
231 Expect.equals(-1, a | b); | 295 Expect.equals(-1, a | b); |
232 } | 296 } |
233 | 297 |
234 testShiftAmount() { | 298 testShiftAmount() { |
235 Expect.equals(0, 12 >> 111111111111111111111111111111); | 299 Expect.equals(0, 12 >> 111111111111111111111111111111); |
(...skipping 11 matching lines...) Expand all Loading... |
247 Expect.equals(1234567890123456789, foo()); | 311 Expect.equals(1234567890123456789, foo()); |
248 Expect.equals(12345678901234567890, bar()); | 312 Expect.equals(12345678901234567890, bar()); |
249 testSmiOverflow(); | 313 testSmiOverflow(); |
250 testBigintAdd(); | 314 testBigintAdd(); |
251 testBigintSub(); | 315 testBigintSub(); |
252 testBigintMul(); | 316 testBigintMul(); |
253 testBigintTruncDiv(); | 317 testBigintTruncDiv(); |
254 testBigintDiv(); | 318 testBigintDiv(); |
255 testBigintModulo(); | 319 testBigintModulo(); |
256 testBigintModPow(); | 320 testBigintModPow(); |
| 321 testBigintModInverse(); |
257 testBigintNegate(); | 322 testBigintNegate(); |
258 testShiftAmount(); | 323 testShiftAmount(); |
259 Expect.equals(12345678901234567890, (12345678901234567890).abs()); | 324 Expect.equals(12345678901234567890, (12345678901234567890).abs()); |
260 Expect.equals(12345678901234567890, (-12345678901234567890).abs()); | 325 Expect.equals(12345678901234567890, (-12345678901234567890).abs()); |
261 var a = 10000000000000000000; | 326 var a = 10000000000000000000; |
262 var b = 10000000000000000001; | 327 var b = 10000000000000000001; |
263 Expect.equals(false, a.hashCode == b.hashCode); | 328 Expect.equals(false, a.hashCode == b.hashCode); |
264 Expect.equals(true, a.hashCode == (b - 1).hashCode); | 329 Expect.equals(true, a.hashCode == (b - 1).hashCode); |
265 } | 330 } |
OLD | NEW |