| 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 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 if (other is int64) { | 231 if (other is int64) { |
| 232 return (this.toInt64() ^ other).toInt32(); | 232 return (this.toInt64() ^ other).toInt32(); |
| 233 } | 233 } |
| 234 return new int32.fromInt(_i ^ _convert(other)); | 234 return new int32.fromInt(_i ^ _convert(other)); |
| 235 } | 235 } |
| 236 | 236 |
| 237 int32 operator ~() => new int32.fromInt(~_i); | 237 int32 operator ~() => new int32.fromInt(~_i); |
| 238 | 238 |
| 239 int32 operator <<(int n) { | 239 int32 operator <<(int n) { |
| 240 if (n < 0) { | 240 if (n < 0) { |
| 241 throw new IllegalArgumentException("$n"); | 241 throw new ArgumentError("$n"); |
| 242 } | 242 } |
| 243 n &= 31; | 243 n &= 31; |
| 244 return new int32.fromInt(_i << n); | 244 return new int32.fromInt(_i << n); |
| 245 } | 245 } |
| 246 | 246 |
| 247 int32 operator >>(int n) { | 247 int32 operator >>(int n) { |
| 248 if (n < 0) { | 248 if (n < 0) { |
| 249 throw new IllegalArgumentException("$n"); | 249 throw new ArgumentError("$n"); |
| 250 } | 250 } |
| 251 n &= 31; | 251 n &= 31; |
| 252 int value; | 252 int value; |
| 253 if (_i >= 0) { | 253 if (_i >= 0) { |
| 254 value = _i >> n; | 254 value = _i >> n; |
| 255 } else { | 255 } else { |
| 256 value = (_i >> n) | (0xffffffff << (32 - n)); | 256 value = (_i >> n) | (0xffffffff << (32 - n)); |
| 257 } | 257 } |
| 258 return new int32.fromInt(value); | 258 return new int32.fromInt(value); |
| 259 } | 259 } |
| 260 | 260 |
| 261 int32 shiftRightUnsigned(int n) { | 261 int32 shiftRightUnsigned(int n) { |
| 262 if (n < 0) { | 262 if (n < 0) { |
| 263 throw new IllegalArgumentException("$n"); | 263 throw new ArgumentError("$n"); |
| 264 } | 264 } |
| 265 n &= 31; | 265 n &= 31; |
| 266 int value; | 266 int value; |
| 267 if (_i >= 0) { | 267 if (_i >= 0) { |
| 268 value = _i >> n; | 268 value = _i >> n; |
| 269 } else { | 269 } else { |
| 270 value = (_i >> n) & ((1 << (32 - n)) - 1); | 270 value = (_i >> n) & ((1 << (32 - n)) - 1); |
| 271 } | 271 } |
| 272 return new int32.fromInt(value); | 272 return new int32.fromInt(value); |
| 273 } | 273 } |
| (...skipping 71 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 |