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

Side by Side Diff: sdk/lib/_internal/compiler/js_lib/js_number.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/integers.dart ('k') | sdk/lib/core/int.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 part of _interceptors; 5 part of _interceptors;
6 6
7 /** 7 /**
8 * The super interceptor class for [JSInt] and [JSDouble]. The compiler 8 * The super interceptor class for [JSInt] and [JSDouble]. The compiler
9 * recognizes this class as an interceptor, and changes references to 9 * recognizes this class as an interceptor, and changes references to
10 * [:this:] to actually use the receiver of the method, which is 10 * [:this:] to actually use the receiver of the method, which is
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 e ~/= 2; 408 e ~/= 2;
409 b = (b * b) % m; 409 b = (b * b) % m;
410 } 410 }
411 return r; 411 return r;
412 } 412 }
413 413
414 // Returns 1/this % m, with m > 0. 414 // Returns 1/this % m, with m > 0.
415 int modInverse(int m) { 415 int modInverse(int m) {
416 if (m is! int) throw new ArgumentError(m); 416 if (m is! int) throw new ArgumentError(m);
417 if (m <= 0) throw new RangeError(m); 417 if (m <= 0) throw new RangeError(m);
418 if (this == 0) return 0;
418 bool ac = m.isEven; 419 bool ac = m.isEven;
419 int u = m; 420 int u = m;
420 int v = this; 421 int v = this;
421 int a = 1, 422 int a = 1,
422 b = 0, 423 b = 0,
423 c = 0, 424 c = 0,
424 d = 1; 425 d = 1;
425 while (u != 0) { 426 while (u != 0) {
426 while (u.isEven) { 427 while (u.isEven) {
427 u ~/= 2; 428 u ~/= 2;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 514 }
514 515
515 class JSDouble extends JSNumber implements double { 516 class JSDouble extends JSNumber implements double {
516 const JSDouble(); 517 const JSDouble();
517 Type get runtimeType => double; 518 Type get runtimeType => double;
518 } 519 }
519 520
520 class JSPositiveInt extends JSInt {} 521 class JSPositiveInt extends JSInt {}
521 class JSUInt32 extends JSPositiveInt {} 522 class JSUInt32 extends JSPositiveInt {}
522 class JSUInt31 extends JSUInt32 {} 523 class JSUInt31 extends JSUInt32 {}
OLDNEW
« no previous file with comments | « runtime/lib/integers.dart ('k') | sdk/lib/core/int.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698