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

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

Issue 1985823002: Cleanup various argument and range errors in double.dart and integers.dart. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: RangeError.range takes minValue and maxValue of type int, not num. Created 4 years, 7 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/double.dart ('k') | no next file » | 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 abstract class _IntegerImplementation { 5 abstract class _IntegerImplementation {
6 // The Dart class _Bigint extending _IntegerImplementation requires a 6 // The Dart class _Bigint extending _IntegerImplementation requires a
7 // default constructor. 7 // default constructor.
8 8
9 Type get runtimeType => int; 9 Type get runtimeType => int;
10 10
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 int ceil() { return this; } 167 int ceil() { return this; }
168 int truncate() { return this; } 168 int truncate() { return this; }
169 169
170 double roundToDouble() { return this.toDouble(); } 170 double roundToDouble() { return this.toDouble(); }
171 double floorToDouble() { return this.toDouble(); } 171 double floorToDouble() { return this.toDouble(); }
172 double ceilToDouble() { return this.toDouble(); } 172 double ceilToDouble() { return this.toDouble(); }
173 double truncateToDouble() { return this.toDouble(); } 173 double truncateToDouble() { return this.toDouble(); }
174 174
175 num clamp(num lowerLimit, num upperLimit) { 175 num clamp(num lowerLimit, num upperLimit) {
176 if (lowerLimit is! num) { 176 if (lowerLimit is! num) {
177 throw new ArgumentError.value(lowerLimit, "lowerLimit"); 177 throw new ArgumentError.value(lowerLimit, "lowerLimit", "not a number");
178 } 178 }
179 if (upperLimit is! num) { 179 if (upperLimit is! num) {
180 throw new ArgumentError.value(upperLimit, "upperLimit"); 180 throw new ArgumentError.value(upperLimit, "upperLimit", "not a number");
181 } 181 }
182 182
183 // Special case for integers. 183 // Special case for integers.
184 if (lowerLimit is int && upperLimit is int && 184 if (lowerLimit is int && upperLimit is int && lowerLimit <= upperLimit) {
185 lowerLimit <= upperLimit) {
186 if (this < lowerLimit) return lowerLimit; 185 if (this < lowerLimit) return lowerLimit;
187 if (this > upperLimit) return upperLimit; 186 if (this > upperLimit) return upperLimit;
188 return this; 187 return this;
189 } 188 }
190 // Generic case involving doubles, and invalid integer ranges. 189 // Generic case involving doubles, and invalid integer ranges.
191 if (lowerLimit.compareTo(upperLimit) > 0) { 190 if (lowerLimit.compareTo(upperLimit) > 0) {
192 throw new RangeError.range(upperLimit, lowerLimit, null, "upperLimit"); 191 throw new ArgumentError(lowerLimit);
193 } 192 }
194 if (lowerLimit.isNaN) return lowerLimit; 193 if (lowerLimit.isNaN) return lowerLimit;
195 // Note that we don't need to care for -0.0 for the lower limit. 194 // Note that we don't need to care for -0.0 for the lower limit.
196 if (this < lowerLimit) return lowerLimit; 195 if (this < lowerLimit) return lowerLimit;
197 if (this.compareTo(upperLimit) > 0) return upperLimit; 196 if (this.compareTo(upperLimit) > 0) return upperLimit;
198 return this; 197 return this;
199 } 198 }
200 199
201 int toInt() { return this; } 200 int toInt() { return this; }
202 double toDouble() { return new _Double.fromInteger(this); } 201 double toDouble() { return new _Double.fromInteger(this); }
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 // Shift by mint exceeds range that can be handled by the VM. 612 // Shift by mint exceeds range that can be handled by the VM.
614 int _shrFromInt(int other) { 613 int _shrFromInt(int other) {
615 if (other < 0) { 614 if (other < 0) {
616 return -1; 615 return -1;
617 } else { 616 } else {
618 return 0; 617 return 0;
619 } 618 }
620 } 619 }
621 int _shlFromInt(int other) native "Mint_shlFromInt"; 620 int _shlFromInt(int other) native "Mint_shlFromInt";
622 } 621 }
OLDNEW
« no previous file with comments | « runtime/lib/double.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698