Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 abstract class _IntegerImplementation { | 5 abstract class _IntegerImplementation { |
| 6 // The Dart class _Bigint extending _IntegerImplementation requires a | 6 // The Dart class _Bigint extending _IntegerImplementation requires a |
| 7 // default constructor. | 7 // default constructor. |
| 8 | 8 |
| 9 num operator +(num other) { | 9 num operator +(num other) { |
| 10 var result = other._addFromInteger(this); | 10 var result = other._addFromInteger(this); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 // Returns gcd of abs(this) and abs(other). | 387 // Returns gcd of abs(this) and abs(other). |
| 388 int gcd(int other) { | 388 int gcd(int other) { |
| 389 if (other is! int) { | 389 if (other is! int) { |
| 390 throw new ArgumentError.value(other, "other", "not an integer"); | 390 throw new ArgumentError.value(other, "other", "not an integer"); |
| 391 } | 391 } |
| 392 int x = this.abs(); | 392 int x = this.abs(); |
| 393 int y = other.abs(); | 393 int y = other.abs(); |
| 394 if (x == 0) return y; | 394 if (x == 0) return y; |
| 395 if (y == 0) return x; | 395 if (y == 0) return x; |
| 396 if ((x == 1) || (y == 1)) return 1; | 396 if ((x == 1) || (y == 1)) return 1; |
| 397 if (other is _Bigint) { | 397 if (y is _Bigint) { |
| 398 return _toBigint().gcd(other); | 398 return x._toBigint().gcd(y); |
|
Lasse Reichstein Nielsen
2016/12/06 09:05:23
If other is -0x8000000000000000 (aka min-mint) the
regis
2016/12/06 17:08:15
Agreed.
| |
| 399 } | 399 } |
| 400 return _binaryGcd(x, y, false); | 400 return _binaryGcd(x, y, false); |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 | 403 |
| 404 class _Smi extends _IntegerImplementation implements int { | 404 class _Smi extends _IntegerImplementation implements int { |
| 405 factory _Smi._uninstantiable() { | 405 factory _Smi._uninstantiable() { |
| 406 throw new UnsupportedError( | 406 throw new UnsupportedError( |
| 407 "_Smi can only be allocated by the VM"); | 407 "_Smi can only be allocated by the VM"); |
| 408 } | 408 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 // Shift by mint exceeds range that can be handled by the VM. | 616 // Shift by mint exceeds range that can be handled by the VM. |
| 617 int _shrFromInt(int other) { | 617 int _shrFromInt(int other) { |
| 618 if (other < 0) { | 618 if (other < 0) { |
| 619 return -1; | 619 return -1; |
| 620 } else { | 620 } else { |
| 621 return 0; | 621 return 0; |
| 622 } | 622 } |
| 623 } | 623 } |
| 624 int _shlFromInt(int other) native "Mint_shlFromInt"; | 624 int _shlFromInt(int other) native "Mint_shlFromInt"; |
| 625 } | 625 } |
| OLD | NEW |