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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 m = 123456789012345678901234567890; | 286 m = 123456789012345678901234567890; |
287 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime. | 287 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime. |
288 x = 123456789012345678901234567891; | 288 x = 123456789012345678901234567891; |
289 m = 123456789012345678901234567890; | 289 m = 123456789012345678901234567890; |
290 Expect.equals(1, x.modInverse(m)); | 290 Expect.equals(1, x.modInverse(m)); |
291 x = 123456789012345678901234567891; | 291 x = 123456789012345678901234567891; |
292 m = 123456789012345678901234567899; | 292 m = 123456789012345678901234567899; |
293 Expect.equals(46296295879629629587962962962, x.modInverse(m)); | 293 Expect.equals(46296295879629629587962962962, x.modInverse(m)); |
294 } | 294 } |
295 | 295 |
| 296 testBigintGcd() { |
| 297 var x, m; |
| 298 x = 1; |
| 299 m = 1; |
| 300 Expect.equals(1, x.gcd(m)); |
| 301 x = 693; |
| 302 m = 609; |
| 303 Expect.equals(21, x.gcd(m)); |
| 304 x = 693 << 40; |
| 305 m = 609 << 40; |
| 306 Expect.equals(21 << 40, x.gcd(m)); |
| 307 x = 609 << 40;; |
| 308 m = 693 << 40;; |
| 309 Expect.equals(21 <<40, x.gcd(m)); |
| 310 x = 0; |
| 311 m = 1000000001; |
| 312 Expect.throws(() => x.gcd(m), (e) => e is RangeError); |
| 313 x = 1000000001; |
| 314 m = 0; |
| 315 Expect.throws(() => x.gcd(m), (e) => e is RangeError); |
| 316 x = 1234567890; |
| 317 m = 19; |
| 318 Expect.equals(1, x.gcd(m)); |
| 319 x = 1234567890; |
| 320 m = 1000000001; |
| 321 Expect.equals(1, x.gcd(m)); |
| 322 x = 19; |
| 323 m = 1000000001; |
| 324 Expect.equals(19, x.gcd(m)); |
| 325 x = 19; |
| 326 m = 1234567890; |
| 327 Expect.equals(1, x.gcd(m)); |
| 328 x = 1000000001; |
| 329 m = 1234567890; |
| 330 Expect.equals(1, x.gcd(m)); |
| 331 x = 1000000001; |
| 332 m = 19; |
| 333 Expect.equals(19, x.gcd(m)); |
| 334 x = 12345678901234567890; |
| 335 m = 19; |
| 336 Expect.equals(1, x.gcd(m)); |
| 337 x = 12345678901234567890; |
| 338 m = 10000000000000000001; |
| 339 Expect.equals(1, x.gcd(m)); |
| 340 x = 19; |
| 341 m = 10000000000000000001; |
| 342 Expect.equals(1, x.gcd(m)); |
| 343 x = 19; |
| 344 m = 12345678901234567890; |
| 345 Expect.equals(1, x.gcd(m)); |
| 346 x = 10000000000000000001; |
| 347 m = 12345678901234567890; |
| 348 Expect.equals(1, x.gcd(m)); |
| 349 x = 10000000000000000001; |
| 350 m = 19; |
| 351 Expect.equals(1, x.gcd(m)); |
| 352 x = 12345678901234567890; |
| 353 m = 10000000000000000001; |
| 354 Expect.equals(1, x.gcd(m)); |
| 355 x = 12345678901234567890; |
| 356 m = 19; |
| 357 Expect.equals(1, x.gcd(m)); |
| 358 x = 123456789012345678901234567890; |
| 359 m = 123456789012345678901234567899; |
| 360 Expect.equals(9, x.gcd(m)); |
| 361 x = 123456789012345678901234567890; |
| 362 m = 123456789012345678901234567891; |
| 363 Expect.equals(1, x.gcd(m)); |
| 364 x = 123456789012345678901234567899; |
| 365 m = 123456789012345678901234567891; |
| 366 Expect.equals(1, x.gcd(m)); |
| 367 x = 123456789012345678901234567899; |
| 368 m = 123456789012345678901234567890; |
| 369 Expect.equals(9, x.gcd(m)); |
| 370 x = 123456789012345678901234567891; |
| 371 m = 123456789012345678901234567890; |
| 372 Expect.equals(1, x.gcd(m)); |
| 373 x = 123456789012345678901234567891; |
| 374 m = 123456789012345678901234567899; |
| 375 Expect.equals(1, x.gcd(m)); |
| 376 } |
| 377 |
296 testBigintNegate() { | 378 testBigintNegate() { |
297 var a = 0xF000000000000000F; | 379 var a = 0xF000000000000000F; |
298 var b = ~a; // negate. | 380 var b = ~a; // negate. |
299 Expect.equals(-0xF0000000000000010, b); | 381 Expect.equals(-0xF0000000000000010, b); |
300 Expect.equals(0, a & b); | 382 Expect.equals(0, a & b); |
301 Expect.equals(-1, a | b); | 383 Expect.equals(-1, a | b); |
302 } | 384 } |
303 | 385 |
304 testShiftAmount() { | 386 testShiftAmount() { |
305 Expect.equals(0, 12 >> 111111111111111111111111111111); | 387 Expect.equals(0, 12 >> 111111111111111111111111111111); |
(...skipping 12 matching lines...) Expand all Loading... |
318 Expect.equals(12345678901234567890, bar()); | 400 Expect.equals(12345678901234567890, bar()); |
319 testSmiOverflow(); | 401 testSmiOverflow(); |
320 testBigintAdd(); | 402 testBigintAdd(); |
321 testBigintSub(); | 403 testBigintSub(); |
322 testBigintMul(); | 404 testBigintMul(); |
323 testBigintTruncDiv(); | 405 testBigintTruncDiv(); |
324 testBigintDiv(); | 406 testBigintDiv(); |
325 testBigintModulo(); | 407 testBigintModulo(); |
326 testBigintModPow(); | 408 testBigintModPow(); |
327 testBigintModInverse(); | 409 testBigintModInverse(); |
| 410 testBigintGcd(); |
328 testBigintNegate(); | 411 testBigintNegate(); |
329 testShiftAmount(); | 412 testShiftAmount(); |
330 Expect.equals(12345678901234567890, (12345678901234567890).abs()); | 413 Expect.equals(12345678901234567890, (12345678901234567890).abs()); |
331 Expect.equals(12345678901234567890, (-12345678901234567890).abs()); | 414 Expect.equals(12345678901234567890, (-12345678901234567890).abs()); |
332 var a = 10000000000000000000; | 415 var a = 10000000000000000000; |
333 var b = 10000000000000000001; | 416 var b = 10000000000000000001; |
334 Expect.equals(false, a.hashCode == b.hashCode); | 417 Expect.equals(false, a.hashCode == b.hashCode); |
335 Expect.equals(true, a.hashCode == (b - 1).hashCode); | 418 Expect.equals(true, a.hashCode == (b - 1).hashCode); |
336 } | 419 } |
OLD | NEW |