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 /** | 5 /** |
6 * An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1]. | 6 * An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1]. |
7 * Arithmetic operations may overflow in order to maintain this range. | 7 * Arithmetic operations may overflow in order to maintain this range. |
8 */ | 8 */ |
9 class int32 implements intx { | 9 class int32 implements intx { |
10 | 10 |
11 /** | 11 /** |
12 * The maximum positive value attainable by an [int32], namely | 12 * The maximum positive value attainable by an [int32], namely |
13 * 2147483647. | 13 * 2147483647. |
14 */ | 14 */ |
15 static final int32 MAX_VALUE = const int32._internal(0x7FFFFFFF); | 15 static const int32 MAX_VALUE = const int32._internal(0x7FFFFFFF); |
16 | 16 |
17 /** | 17 /** |
18 * The minimum positive value attainable by an [int32], namely | 18 * The minimum positive value attainable by an [int32], namely |
19 * -2147483648. | 19 * -2147483648. |
20 */ | 20 */ |
21 static int32 MIN_VALUE = const int32._internal(0x80000000); | 21 static int32 MIN_VALUE = const int32._internal(0x80000000); |
22 | 22 |
23 /** | 23 /** |
24 * An [int32] constant equal to 0. | 24 * An [int32] constant equal to 0. |
25 */ | 25 */ |
26 static int32 ZERO = const int32._internal(0); | 26 static int32 ZERO = const int32._internal(0); |
27 | 27 |
28 /** | 28 /** |
29 * An [int32] constant equal to 1. | 29 * An [int32] constant equal to 1. |
30 */ | 30 */ |
31 static int32 ONE = const int32._internal(1); | 31 static int32 ONE = const int32._internal(1); |
32 | 32 |
33 /** | 33 /** |
34 * An [int32] constant equal to 2. | 34 * An [int32] constant equal to 2. |
35 */ | 35 */ |
36 static int32 TWO = const int32._internal(2); | 36 static int32 TWO = const int32._internal(2); |
37 | 37 |
38 // Hex digit char codes | 38 // Hex digit char codes |
39 static final int _CC_0 = 48; // '0'.charCodeAt(0) | 39 static const int _CC_0 = 48; // '0'.charCodeAt(0) |
40 static final int _CC_9 = 57; // '9'.charCodeAt(0) | 40 static const int _CC_9 = 57; // '9'.charCodeAt(0) |
41 static final int _CC_a = 97; // 'a'.charCodeAt(0) | 41 static const int _CC_a = 97; // 'a'.charCodeAt(0) |
42 static final int _CC_z = 122; // 'z'.charCodeAt(0) | 42 static const int _CC_z = 122; // 'z'.charCodeAt(0) |
43 static final int _CC_A = 65; // 'A'.charCodeAt(0) | 43 static const int _CC_A = 65; // 'A'.charCodeAt(0) |
44 static final int _CC_Z = 90; // 'Z'.charCodeAt(0) | 44 static const int _CC_Z = 90; // 'Z'.charCodeAt(0) |
45 | 45 |
46 static int _decodeHex(int c) { | 46 static int _decodeHex(int c) { |
47 if (c >= _CC_0 && c <= _CC_9) { | 47 if (c >= _CC_0 && c <= _CC_9) { |
48 return c - _CC_0; | 48 return c - _CC_0; |
49 } else if (c >= _CC_a && c <= _CC_z) { | 49 } else if (c >= _CC_a && c <= _CC_z) { |
50 return c - _CC_a + 10; | 50 return c - _CC_a + 10; |
51 } else if (c >= _CC_A && c <= _CC_Z) { | 51 } else if (c >= _CC_A && c <= _CC_Z) { |
52 return c - _CC_A + 10; | 52 return c - _CC_A + 10; |
53 } else { | 53 } else { |
54 return -1; // bad char code | 54 return -1; // bad char code |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 345 } |
346 | 346 |
347 int toInt() => _i; | 347 int toInt() => _i; |
348 int32 toInt32() => this; | 348 int32 toInt32() => this; |
349 int64 toInt64() => new int64.fromInt(_i); | 349 int64 toInt64() => new int64.fromInt(_i); |
350 | 350 |
351 String toString() => _i.toString(); | 351 String toString() => _i.toString(); |
352 String toHexString() => _i.toRadixString(16); | 352 String toHexString() => _i.toRadixString(16); |
353 String toRadixString(int radix) => _i.toRadixString(radix); | 353 String toRadixString(int radix) => _i.toRadixString(radix); |
354 } | 354 } |
OLD | NEW |