| 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 // TODO(srdjan): fix limitations. | 5 // TODO(srdjan): fix limitations. |
| 6 // - shift amount must be a Smi. | 6 // - shift amount must be a Smi. |
| 7 class _IntegerImplementation extends _Num { | 7 class _IntegerImplementation extends _Num { |
| 8 // The Dart class _Bigint extending _IntegerImplementation requires a | 8 // The Dart class _Bigint extending _IntegerImplementation requires a |
| 9 // default constructor. | 9 // default constructor. |
| 10 | 10 |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 throw new UnsupportedError("Not coprime"); | 384 throw new UnsupportedError("Not coprime"); |
| 385 } | 385 } |
| 386 return _binaryGcd(m, t, true); | 386 return _binaryGcd(m, t, true); |
| 387 } | 387 } |
| 388 | 388 |
| 389 // Returns gcd of abs(this) and abs(other), with this != 0 and other !=0. | 389 // Returns gcd of abs(this) and abs(other), with this != 0 and other !=0. |
| 390 int gcd(int other) { | 390 int gcd(int other) { |
| 391 if (other is! int) { | 391 if (other is! int) { |
| 392 throw new ArgumentError.value(other, "other", "not an integer"); | 392 throw new ArgumentError.value(other, "other", "not an integer"); |
| 393 } | 393 } |
| 394 if (this == 0) { | 394 if ((this == 0) && (other == 0)) { |
| 395 throw new ArgumentError.value(this, "first operand", "must not be zero"); | 395 throw new ArgumentError.value(0, null, |
| 396 } | 396 "at least one operand must not be zero"); |
| 397 if (other == 0) { | |
| 398 throw new ArgumentError.value(this, "second operand", "must not be zero"); | |
| 399 } | 397 } |
| 400 int x = this.abs(); | 398 int x = this.abs(); |
| 401 int y = other.abs(); | 399 int y = other.abs(); |
| 400 if (x == 0) return y; |
| 401 if (y == 0) return x; |
| 402 if ((x == 1) || (y == 1)) return 1; | 402 if ((x == 1) || (y == 1)) return 1; |
| 403 if (other is _Bigint) { | 403 if (other is _Bigint) { |
| 404 return _toBigint().gcd(other); | 404 return _toBigint().gcd(other); |
| 405 } | 405 } |
| 406 return _binaryGcd(x, y, false); | 406 return _binaryGcd(x, y, false); |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 | 409 |
| 410 class _Smi extends _IntegerImplementation implements int { | 410 class _Smi extends _IntegerImplementation implements int { |
| 411 factory _Smi._uninstantiable() { | 411 factory _Smi._uninstantiable() { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 // Shift by mint exceeds range that can be handled by the VM. | 619 // Shift by mint exceeds range that can be handled by the VM. |
| 620 int _shrFromInt(int other) { | 620 int _shrFromInt(int other) { |
| 621 if (other < 0) { | 621 if (other < 0) { |
| 622 return -1; | 622 return -1; |
| 623 } else { | 623 } else { |
| 624 return 0; | 624 return 0; |
| 625 } | 625 } |
| 626 } | 626 } |
| 627 int _shlFromInt(int other) native "Mint_shlFromInt"; | 627 int _shlFromInt(int other) native "Mint_shlFromInt"; |
| 628 } | 628 } |
| OLD | NEW |