Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: runtime/lib/integers.dart

Issue 1177063002: Detect zero receiver of modInverse (may not converge and time out (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/lib/bigint.dart ('k') | sdk/lib/_internal/compiler/js_lib/js_number.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « runtime/lib/bigint.dart ('k') | sdk/lib/_internal/compiler/js_lib/js_number.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698