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 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 } | 1535 } |
1536 } | 1536 } |
1537 assert(!is1); | 1537 assert(!is1); |
1538 return z._revert(r_digits, r_used)._toValidInt(); | 1538 return z._revert(r_digits, r_used)._toValidInt(); |
1539 } | 1539 } |
1540 | 1540 |
1541 // Returns 1/this % m, with m > 0. | 1541 // Returns 1/this % m, with m > 0. |
1542 int modInverse(int m) { | 1542 int modInverse(int m) { |
1543 if (m is! int) throw new ArgumentError(m); | 1543 if (m is! int) throw new ArgumentError(m); |
1544 if (m <= 0) throw new RangeError(m); | 1544 if (m <= 0) throw new RangeError(m); |
| 1545 if (_used == 0) return 0; |
1545 m = m._toBigint(); | 1546 m = m._toBigint(); |
1546 // TODO(regis): Implement modInverse for an even modulus. | 1547 // TODO(regis): Implement modInverse for an even modulus. |
1547 if (m.isEven) throw new UnimplementedError(); | 1548 if (m.isEven) throw new UnimplementedError(); |
1548 var t = this; | 1549 var t = this; |
1549 if ((t._compare(m) >= 0) || t._neg) { | 1550 if ((t._compare(m) >= 0) || t._neg) { |
1550 t %= m; | 1551 t %= m; |
1551 t = t._toBigint(); | 1552 t = t._toBigint(); |
1552 } | 1553 } |
1553 final t_used = t._used; | 1554 final t_used = t._used; |
1554 if (t_used == 0) { | 1555 if (t_used == 0) { |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1907 | 1908 |
1908 int _mul(Uint32List x_digits, int x_used, | 1909 int _mul(Uint32List x_digits, int x_used, |
1909 Uint32List y_digits, int y_used, | 1910 Uint32List y_digits, int y_used, |
1910 Uint32List r_digits) { | 1911 Uint32List r_digits) { |
1911 var r_used = _Bigint._mulDigits(x_digits, x_used, | 1912 var r_used = _Bigint._mulDigits(x_digits, x_used, |
1912 y_digits, y_used, | 1913 y_digits, y_used, |
1913 r_digits); | 1914 r_digits); |
1914 return _reduce(r_digits, r_used); | 1915 return _reduce(r_digits, r_used); |
1915 } | 1916 } |
1916 } | 1917 } |
OLD | NEW |