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

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

Issue 821123003: Simplify double to bigint conversion. (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
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 193 }
194 if (lowerLimit.isNaN) return lowerLimit; 194 if (lowerLimit.isNaN) return lowerLimit;
195 // Note that we don't need to care for -0.0 for the lower limit. 195 // Note that we don't need to care for -0.0 for the lower limit.
196 if (this < lowerLimit) return lowerLimit; 196 if (this < lowerLimit) return lowerLimit;
197 if (this.compareTo(upperLimit) > 0) return upperLimit; 197 if (this.compareTo(upperLimit) > 0) return upperLimit;
198 return this; 198 return this;
199 } 199 }
200 200
201 int toInt() { return this; } 201 int toInt() { return this; }
202 double toDouble() { return new _Double.fromInteger(this); } 202 double toDouble() { return new _Double.fromInteger(this); }
203 _Bigint _toBigint() { return new _Bigint()._setInt(this); } 203 _Bigint _toBigint() { return new _Bigint._fromInt(this); }
204 num _toBigintOrDouble() { return _toBigint(); } 204 num _toBigintOrDouble() { return _toBigint(); }
205 205
206 String toStringAsFixed(int fractionDigits) { 206 String toStringAsFixed(int fractionDigits) {
207 return this.toDouble().toStringAsFixed(fractionDigits); 207 return this.toDouble().toStringAsFixed(fractionDigits);
208 } 208 }
209 String toStringAsExponential([int fractionDigits]) { 209 String toStringAsExponential([int fractionDigits]) {
210 return this.toDouble().toStringAsExponential(fractionDigits); 210 return this.toDouble().toStringAsExponential(fractionDigits);
211 } 211 }
212 String toStringAsPrecision(int precision) { 212 String toStringAsPrecision(int precision) {
213 return this.toDouble().toStringAsPrecision(precision); 213 return this.toDouble().toStringAsPrecision(precision);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 // Shift by mint exceeds range that can be handled by the VM. 503 // Shift by mint exceeds range that can be handled by the VM.
504 int _shrFromInt(int other) { 504 int _shrFromInt(int other) {
505 if (other < 0) { 505 if (other < 0) {
506 return -1; 506 return -1;
507 } else { 507 } else {
508 return 0; 508 return 0;
509 } 509 }
510 } 510 }
511 int _shlFromInt(int other) native "Mint_shlFromInt"; 511 int _shlFromInt(int other) native "Mint_shlFromInt";
512 } 512 }
OLDNEW
« runtime/lib/bigint.dart ('K') | « runtime/lib/double.cc ('k') | runtime/vm/exceptions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698