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

Side by Side Diff: lib/fixnum/int32.dart

Issue 10595002: Protocol Buffer runtime library and 'protoc' plugin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Work around http://code.google.com/p/dart/issues/detail?id=3806 Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/fixnum/int64.dart » ('j') | 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 /** 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 */ 136 */
137 int32.fromInt(int i) : _i = (i & 0x7fffffff) - (i & 0x80000000); 137 int32.fromInt(int i) : _i = (i & 0x7fffffff) - (i & 0x80000000);
138 138
139 // Convert an [int] or [intx] to an [int32]. Note that an [int64] 139 // Convert an [int] or [intx] to an [int32]. Note that an [int64]
140 // will be truncated. 140 // will be truncated.
141 int _convert(other) { 141 int _convert(other) {
142 if (other == null) { 142 if (other == null) {
143 throw new NullPointerException(); 143 throw new NullPointerException();
144 } else if (other is intx) { 144 } else if (other is intx) {
145 return other.toInt32()._i; 145 return other.toInt32()._i;
146 } else if (other is int) { 146 } else if (other is num) {
147 return other; 147 return other.toInt();
148 } else { 148 } else {
149 throw new Exception("Can't retrieve 32-bit int from $other"); 149 throw new Exception("Can't retrieve 32-bit int from $other");
150 } 150 }
151 } 151 }
152 152
153 // The +, -, * , &, |, and ^ operaters deal with types as follows: 153 // The +, -, * , &, |, and ^ operaters deal with types as follows:
154 // 154 //
155 // int32 + int => int32 155 // int32 + int => int32
156 // int32 + int32 => int32 156 // int32 + int32 => int32
157 // int32 + int64 => int64 157 // int32 + int64 => int64
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « no previous file | lib/fixnum/int64.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698