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

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

Issue 842033005: Make Bigint instances immutable by removing all setters. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 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
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 var mask = radix - 1; 258 var mask = radix - 1;
259 do { 259 do {
260 string._setAt(--length, _digits.codeUnitAt(value & mask)); 260 string._setAt(--length, _digits.codeUnitAt(value & mask));
261 value >>= bitsPerDigit; 261 value >>= bitsPerDigit;
262 } while (value > 0); 262 } while (value > 0);
263 return string; 263 return string;
264 } 264 }
265 265
266 _leftShiftWithMask32(count, mask) native "Integer_leftShiftWithMask32"; 266 _leftShiftWithMask32(count, mask) native "Integer_leftShiftWithMask32";
267 267
268 // TODO(regis): Make this method private once the plumbing to invoke it from
269 // dart:math is in place. Move the argument checking to dart:math.
270 // Return pow(this, e) % m. 268 // Return pow(this, e) % m.
271 int modPow(int e, int m) { 269 int modPow(int e, int m) {
272 if (e is! int) throw new ArgumentError(e); 270 if (e is! int || e < 0) throw new ArgumentError(e);
273 if (m is! int) throw new ArgumentError(m); 271 if (m is! int || m <= 0) throw new ArgumentError(m);
274 if (e is _Bigint || m is _Bigint) { 272 if (e is _Bigint || m is _Bigint) {
275 return _toBigint().modPow(e, m); 273 return _toBigint().modPow(e, m);
276 } 274 }
277 if (e < 1) return 1; 275 if (e < 1) return 1;
278 int b = this; 276 int b = this;
279 if (b < 0 || b > m) { 277 if (b < 0 || b > m) {
280 b = b % m; 278 b = b % m;
281 } 279 }
282 int r = 1; 280 int r = 1;
283 while (e > 0) { 281 while (e > 0) {
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 // Shift by mint exceeds range that can be handled by the VM. 501 // Shift by mint exceeds range that can be handled by the VM.
504 int _shrFromInt(int other) { 502 int _shrFromInt(int other) {
505 if (other < 0) { 503 if (other < 0) {
506 return -1; 504 return -1;
507 } else { 505 } else {
508 return 0; 506 return 0;
509 } 507 }
510 } 508 }
511 int _shlFromInt(int other) native "Mint_shlFromInt"; 509 int _shlFromInt(int other) native "Mint_shlFromInt";
512 } 510 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698