| 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 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 int _remainderFromInteger(int other) { | 1331 int _remainderFromInteger(int other) { |
| 1332 return other._toBigint()._rem(this)._toValidInt(); | 1332 return other._toBigint()._rem(this)._toValidInt(); |
| 1333 } | 1333 } |
| 1334 bool _greaterThanFromInteger(int other) { | 1334 bool _greaterThanFromInteger(int other) { |
| 1335 return other._toBigint()._compare(this) > 0; | 1335 return other._toBigint()._compare(this) > 0; |
| 1336 } | 1336 } |
| 1337 bool _equalToInteger(int other) { | 1337 bool _equalToInteger(int other) { |
| 1338 return other._toBigint()._compare(this) == 0; | 1338 return other._toBigint()._compare(this) == 0; |
| 1339 } | 1339 } |
| 1340 | 1340 |
| 1341 // Return pow(this, e) % m, with e >= 0, m > 0. | 1341 // Returns pow(this, e) % m, with e >= 0, m > 0. |
| 1342 int modPow(int e, int m) { | 1342 int modPow(int e, int m) { |
| 1343 if (e is! int || e < 0) throw new ArgumentError(e); | 1343 if (e is! int) throw new ArgumentError(e); |
| 1344 if (m is! int || m <= 0) throw new ArgumentError(m); | 1344 if (m is! int) throw new ArgumentError(m); |
| 1345 if (e < 0) throw new RangeError(e); |
| 1346 if (m <= 0) throw new RangeError(m); |
| 1347 if (e == 0) return 1; |
| 1345 final m_used = m._used; | 1348 final m_used = m._used; |
| 1346 final m_used2p2 = 2*m_used + 1 + 1; // +1 for leading zero. | 1349 final m_used2p2 = 2*m_used + 1 + 1; // +1 for leading zero. |
| 1347 final e_bitlen = e.bitLength; | 1350 final e_bitlen = e.bitLength; |
| 1348 if (e_bitlen <= 0) return 1; | 1351 if (e_bitlen <= 0) return 1; |
| 1349 if ((e is! _Bigint) || m.isEven) { | 1352 if ((e is! _Bigint) || m.isEven) { |
| 1350 _Reduction z = (e_bitlen < 8 || m.isEven) ? | 1353 _Reduction z = (e_bitlen < 8 || m.isEven) ? |
| 1351 new _Classic(m) : new _Montgomery(m); | 1354 new _Classic(m) : new _Montgomery(m); |
| 1352 // TODO(regis): Should we use Barrett reduction for an even modulus? | 1355 // TODO(regis): Should we use Barrett reduction for an even modulus? |
| 1353 var m_used = m._used; | 1356 var m_used = m._used; |
| 1354 var r_digits = new Uint32List(m_used2p2); | 1357 var r_digits = new Uint32List(m_used2p2); |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1738 | 1741 |
| 1739 int _mul(Uint32List x_digits, int x_used, | 1742 int _mul(Uint32List x_digits, int x_used, |
| 1740 Uint32List y_digits, int y_used, | 1743 Uint32List y_digits, int y_used, |
| 1741 Uint32List r_digits) { | 1744 Uint32List r_digits) { |
| 1742 var r_used = _Bigint._mulDigits(x_digits, x_used, | 1745 var r_used = _Bigint._mulDigits(x_digits, x_used, |
| 1743 y_digits, y_used, | 1746 y_digits, y_used, |
| 1744 r_digits); | 1747 r_digits); |
| 1745 return _reduce(r_digits, r_used); | 1748 return _reduce(r_digits, r_used); |
| 1746 } | 1749 } |
| 1747 } | 1750 } |
| OLD | NEW |