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

Unified Diff: lib/src/int32.dart

Issue 1834783004: Merge in changes from SDK branch (Closed) Base URL: https://github.com/dart-lang/fixnum@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « README.md ('k') | lib/src/int64.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/int32.dart
diff --git a/lib/src/int32.dart b/lib/src/int32.dart
index 32f362097140d30b0efddd3e88c9ef2cdde4334e..c5996f8aa797e289703e44643b6f1f7a323bb659 100644
--- a/lib/src/int32.dart
+++ b/lib/src/int32.dart
@@ -57,15 +57,18 @@ class Int32 implements IntX {
}
}
+ static int _validateRadix(int radix) {
+ if (2 <= radix && radix <= 36) return radix;
+ throw new RangeError.range(radix, 2, 36, 'radix');
+ }
+
/**
* Parses a [String] in a given [radix] between 2 and 16 and returns an
* [Int32].
*/
// TODO(rice) - Make this faster by converting several digits at once.
static Int32 parseRadix(String s, int radix) {
- if ((radix <= 1) || (radix > 16)) {
- throw new ArgumentError("Bad radix: $radix");
- }
+ _validateRadix(radix);
Int32 x = ZERO;
for (int i = 0; i < s.length; i++) {
int c = s.codeUnitAt(i);
@@ -348,12 +351,12 @@ class Int32 implements IntX {
int numberOfTrailingZeros() => _numberOfTrailingZeros(_i);
Int32 toSigned(int width) {
- if (width < 1 || width > 32) throw new ArgumentError(width);
+ if (width < 1 || width > 32) throw new RangeError.range(width, 1, 32);
return new Int32(_i.toSigned(width));
}
Int32 toUnsigned(int width) {
- if (width < 0 || width > 32) throw new ArgumentError(width);
+ if (width < 0 || width > 32) throw new RangeError.range(width, 0, 32);
return new Int32(_i.toUnsigned(width));
}
« no previous file with comments | « README.md ('k') | lib/src/int64.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698