OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Copyright 2009 The Go Authors. All rights reserved. | 5 // Copyright 2009 The Go Authors. All rights reserved. |
6 // Use of this source code is governed by a BSD-style | 6 // Use of this source code is governed by a BSD-style |
7 // license that can be found in the LICENSE file. | 7 // license that can be found in the LICENSE file. |
8 | 8 |
9 /* | 9 /* |
10 * Copyright (c) 2003-2005 Tom Wu | 10 * Copyright (c) 2003-2005 Tom Wu |
(...skipping 1793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1804 if (m == 1) return 0; | 1804 if (m == 1) return 0; |
1805 m = m._toBigint(); | 1805 m = m._toBigint(); |
1806 var t = this; | 1806 var t = this; |
1807 if (t._neg || (t._absCompare(m) >= 0)) { | 1807 if (t._neg || (t._absCompare(m) >= 0)) { |
1808 t %= m; | 1808 t %= m; |
1809 t = t._toBigint(); | 1809 t = t._toBigint(); |
1810 } | 1810 } |
1811 return _binaryGcd(m, t, true); | 1811 return _binaryGcd(m, t, true); |
1812 } | 1812 } |
1813 | 1813 |
1814 // Returns gcd of abs(this) and abs(other), with this != 0 and other !=0. | 1814 // Returns gcd of abs(this) and abs(other). |
1815 int gcd(int other) { | 1815 int gcd(int other) { |
1816 if (other is! int) { | 1816 if (other is! int) { |
1817 throw new ArgumentError.value(other, "other", "not an integer"); | 1817 throw new ArgumentError.value(other, "other", "not an integer"); |
1818 } | 1818 } |
| 1819 if (other == 0) { |
| 1820 return this.abs(); |
| 1821 } |
1819 return _binaryGcd(this, other._toBigint(), false); | 1822 return _binaryGcd(this, other._toBigint(), false); |
1820 } | 1823 } |
1821 } | 1824 } |
1822 | 1825 |
1823 // Interface for modular reduction. | 1826 // Interface for modular reduction. |
1824 class _Reduction { | 1827 class _Reduction { |
1825 // Return the number of digits used by r_digits. | 1828 // Return the number of digits used by r_digits. |
1826 int _convert(_Bigint x, Uint32List r_digits); | 1829 int _convert(_Bigint x, Uint32List r_digits); |
1827 int _mul(Uint32List x_digits, int x_used, | 1830 int _mul(Uint32List x_digits, int x_used, |
1828 Uint32List y_digits, int y_used, Uint32List r_digits); | 1831 Uint32List y_digits, int y_used, Uint32List r_digits); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2087 | 2090 |
2088 int _mul(Uint32List x_digits, int x_used, | 2091 int _mul(Uint32List x_digits, int x_used, |
2089 Uint32List y_digits, int y_used, | 2092 Uint32List y_digits, int y_used, |
2090 Uint32List r_digits) { | 2093 Uint32List r_digits) { |
2091 var r_used = _Bigint._mulDigits(x_digits, x_used, | 2094 var r_used = _Bigint._mulDigits(x_digits, x_used, |
2092 y_digits, y_used, | 2095 y_digits, y_used, |
2093 r_digits); | 2096 r_digits); |
2094 return _reduce(r_digits, r_used); | 2097 return _reduce(r_digits, r_used); |
2095 } | 2098 } |
2096 } | 2099 } |
OLD | NEW |