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

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

Issue 834323002: Add modPow(int exponent, int modulus) method to int abstract class. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/integers.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) 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 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 other._toBigint()._divRemTo(this, null, result); 1321 other._toBigint()._divRemTo(this, null, result);
1322 return result._toValidInt(); 1322 return result._toValidInt();
1323 } 1323 }
1324 bool _greaterThanFromInteger(int other) { 1324 bool _greaterThanFromInteger(int other) {
1325 return other._toBigint()._compareTo(this) > 0; 1325 return other._toBigint()._compareTo(this) > 0;
1326 } 1326 }
1327 bool _equalToInteger(int other) { 1327 bool _equalToInteger(int other) {
1328 return other._toBigint()._compareTo(this) == 0; 1328 return other._toBigint()._compareTo(this) == 0;
1329 } 1329 }
1330 1330
1331 // TODO(regis): Make this method private once the plumbing to invoke it from
1332 // dart:math is in place. Move the argument checking to dart:math.
1333 // Return pow(this, e) % m. 1331 // Return pow(this, e) % m.
1334 int modPow(int e, int m) { 1332 int modPow(int e, int m) {
1335 if (e is! int) throw new ArgumentError(e); 1333 if (e is! int) throw new ArgumentError(e);
1336 if (m is! int) throw new ArgumentError(m); 1334 if (m is! int) throw new ArgumentError(m);
1337 int i = e.bitLength; 1335 int i = e.bitLength;
1338 if (i <= 0) return 1; 1336 if (i <= 0) return 1;
1339 if ((e is! _Bigint) || m.isEven) { 1337 if ((e is! _Bigint) || m.isEven) {
1340 _Reduction z = (i < 8 || m.isEven) ? new _Classic(m) : new _Montgomery(m); 1338 _Reduction z = (i < 8 || m.isEven) ? new _Classic(m) : new _Montgomery(m);
1341 // TODO(regis): Should we use Barrett reduction for an even modulus? 1339 // TODO(regis): Should we use Barrett reduction for an even modulus?
1342 var r = new _Bigint(); 1340 var r = new _Bigint();
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 void _sqrTo(_Bigint x, _Bigint r) { 1625 void _sqrTo(_Bigint x, _Bigint r) {
1628 x._sqrTo(r); 1626 x._sqrTo(r);
1629 _reduce(r); 1627 _reduce(r);
1630 } 1628 }
1631 1629
1632 void _mulTo(_Bigint x, _Bigint y, _Bigint r) { 1630 void _mulTo(_Bigint x, _Bigint y, _Bigint r) {
1633 x._mulTo(y, r); 1631 x._mulTo(y, r);
1634 _reduce(r); 1632 _reduce(r);
1635 } 1633 }
1636 } 1634 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/integers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698