| 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 part of _interceptors; | 5 part of _interceptors; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The super interceptor class for [JSInt] and [JSDouble]. The compiler | 8 * The super interceptor class for [JSInt] and [JSDouble]. The compiler |
| 9 * recognizes this class as an interceptor, and changes references to | 9 * recognizes this class as an interceptor, and changes references to |
| 10 * [:this:] to actually use the receiver of the method, which is | 10 * [:this:] to actually use the receiver of the method, which is |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 throw new UnsupportedError("Not coprime"); | 497 throw new UnsupportedError("Not coprime"); |
| 498 } | 498 } |
| 499 return _binaryGcd(m, t, true); | 499 return _binaryGcd(m, t, true); |
| 500 } | 500 } |
| 501 | 501 |
| 502 // Returns gcd of abs(this) and abs(other), with this != 0 and other !=0. | 502 // Returns gcd of abs(this) and abs(other), with this != 0 and other !=0. |
| 503 int gcd(int other) { | 503 int gcd(int other) { |
| 504 if (m is! int) { | 504 if (m is! int) { |
| 505 throw new ArgumentError.value(m, "other", "not an integer"); | 505 throw new ArgumentError.value(m, "other", "not an integer"); |
| 506 } | 506 } |
| 507 if (this == 0) { | 507 if (this == 0 && other == 0) { |
| 508 throw new ArgumentError.value(this, "first operand", "must not be zero"); | 508 throw new ArgumentError.value(this, null, |
| 509 } | 509 "at least one operand must not be zero"); |
| 510 if (other == 0) { | |
| 511 throw new ArgumentError.value(this, "second operand", "must not be zero"); | |
| 512 } | 510 } |
| 513 int x = this.abs(); | 511 int x = this.abs(); |
| 514 int y = other.abs(); | 512 int y = other.abs(); |
| 513 if (x == 0) return y; |
| 514 if (y == 0) return x; |
| 515 if ((x == 1) || (y == 1)) return 1; | 515 if ((x == 1) || (y == 1)) return 1; |
| 516 return _binaryGcd(x, y, false); | 516 return _binaryGcd(x, y, false); |
| 517 } | 517 } |
| 518 | 518 |
| 519 // Assumes i is <= 32-bit and unsigned. | 519 // Assumes i is <= 32-bit and unsigned. |
| 520 static int _bitCount(int i) { | 520 static int _bitCount(int i) { |
| 521 // See "Hacker's Delight", section 5-1, "Counting 1-Bits". | 521 // See "Hacker's Delight", section 5-1, "Counting 1-Bits". |
| 522 | 522 |
| 523 // The basic strategy is to use "divide and conquer" to | 523 // The basic strategy is to use "divide and conquer" to |
| 524 // add pairs (then quads, etc.) of bits together to obtain | 524 // add pairs (then quads, etc.) of bits together to obtain |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 } | 563 } |
| 564 | 564 |
| 565 class JSDouble extends JSNumber implements double { | 565 class JSDouble extends JSNumber implements double { |
| 566 const JSDouble(); | 566 const JSDouble(); |
| 567 Type get runtimeType => double; | 567 Type get runtimeType => double; |
| 568 } | 568 } |
| 569 | 569 |
| 570 class JSPositiveInt extends JSInt {} | 570 class JSPositiveInt extends JSInt {} |
| 571 class JSUInt32 extends JSPositiveInt {} | 571 class JSUInt32 extends JSPositiveInt {} |
| 572 class JSUInt31 extends JSUInt32 {} | 572 class JSUInt31 extends JSUInt32 {} |
| OLD | NEW |