OLD | NEW |
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 part of fixnum; | 5 part of fixnum; |
6 | 6 |
7 /** | 7 /** |
8 * An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1]. | 8 * An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1]. |
9 * Arithmetic operations may overflow in order to maintain this range. | 9 * Arithmetic operations may overflow in order to maintain this range. |
10 */ | 10 */ |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // TODO(rice) - Make this faster by converting several digits at once. | 64 // TODO(rice) - Make this faster by converting several digits at once. |
65 static Int32 parseRadix(String s, int radix) { | 65 static Int32 parseRadix(String s, int radix) { |
66 if ((radix <= 1) || (radix > 16)) { | 66 if ((radix <= 1) || (radix > 16)) { |
67 throw new ArgumentError("Bad radix: $radix"); | 67 throw new ArgumentError("Bad radix: $radix"); |
68 } | 68 } |
69 Int32 x = ZERO; | 69 Int32 x = ZERO; |
70 for (int i = 0; i < s.length; i++) { | 70 for (int i = 0; i < s.length; i++) { |
71 int c = s.codeUnitAt(i); | 71 int c = s.codeUnitAt(i); |
72 int digit = _decodeDigit(c); | 72 int digit = _decodeDigit(c); |
73 if (digit < 0 || digit >= radix) { | 73 if (digit < 0 || digit >= radix) { |
74 throw new Exception("Non-radix code unit: $c"); | 74 throw new FormatException("Non-radix code unit: $c"); |
75 } | 75 } |
76 x = (x * radix) + digit; | 76 x = (x * radix) + digit; |
77 } | 77 } |
78 return x; | 78 return x; |
79 } | 79 } |
80 | 80 |
81 /** | 81 /** |
82 * Parses a decimal [String] and returns an [Int32]. | 82 * Parses a decimal [String] and returns an [Int32]. |
83 */ | 83 */ |
84 static Int32 parseInt(String s) => new Int32(int.parse(s)); | 84 static Int32 parseInt(String s) => new Int32(int.parse(s)); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 375 |
376 double toDouble() => _i.toDouble(); | 376 double toDouble() => _i.toDouble(); |
377 int toInt() => _i; | 377 int toInt() => _i; |
378 Int32 toInt32() => this; | 378 Int32 toInt32() => this; |
379 Int64 toInt64() => new Int64(_i); | 379 Int64 toInt64() => new Int64(_i); |
380 | 380 |
381 String toString() => _i.toString(); | 381 String toString() => _i.toString(); |
382 String toHexString() => _i.toRadixString(16); | 382 String toHexString() => _i.toRadixString(16); |
383 String toRadixString(int radix) => _i.toRadixString(radix); | 383 String toRadixString(int radix) => _i.toRadixString(radix); |
384 } | 384 } |
OLD | NEW |