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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 return r; | 290 return r; |
291 } | 291 } |
292 | 292 |
293 // Returns 1/this % m, with m > 0. | 293 // Returns 1/this % m, with m > 0. |
294 int modInverse(int m) { | 294 int modInverse(int m) { |
295 if (m is! int) throw new ArgumentError(m); | 295 if (m is! int) throw new ArgumentError(m); |
296 if (m <= 0) throw new RangeError(m); | 296 if (m <= 0) throw new RangeError(m); |
297 if (m is _Bigint) { | 297 if (m is _Bigint) { |
298 return _toBigint().modInverse(m); | 298 return _toBigint().modInverse(m); |
299 } | 299 } |
| 300 if (this == 0) return 0; |
300 bool ac = m.isEven; | 301 bool ac = m.isEven; |
301 int u = m; | 302 int u = m; |
302 int v = this; | 303 int v = this; |
303 int a = 1, | 304 int a = 1, |
304 b = 0, | 305 b = 0, |
305 c = 0, | 306 c = 0, |
306 d = 1; | 307 d = 1; |
307 while (u != 0) { | 308 while (u != 0) { |
308 while (u.isEven) { | 309 while (u.isEven) { |
309 u >>= 1; | 310 u >>= 1; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 // Shift by mint exceeds range that can be handled by the VM. | 562 // Shift by mint exceeds range that can be handled by the VM. |
562 int _shrFromInt(int other) { | 563 int _shrFromInt(int other) { |
563 if (other < 0) { | 564 if (other < 0) { |
564 return -1; | 565 return -1; |
565 } else { | 566 } else { |
566 return 0; | 567 return 0; |
567 } | 568 } |
568 } | 569 } |
569 int _shlFromInt(int other) native "Mint_shlFromInt"; | 570 int _shlFromInt(int other) native "Mint_shlFromInt"; |
570 } | 571 } |
OLD | NEW |