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 // TODO(srdjan): fix limitations. | 5 // TODO(srdjan): fix limitations. |
6 // - shift amount must be a Smi. | 6 // - shift amount must be a Smi. |
7 class _IntegerImplementation { | 7 class _IntegerImplementation { |
8 factory _IntegerImplementation._uninstantiable() { | 8 factory _IntegerImplementation._uninstantiable() { |
9 throw new UnsupportedError( | 9 throw new UnsupportedError( |
10 "_IntegerImplementation can only be allocated by the VM"); | 10 "_IntegerImplementation can only be allocated by the VM"); |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 negative = true; | 268 negative = true; |
269 // Handle the first digit as negative to avoid negating the minimum | 269 // Handle the first digit as negative to avoid negating the minimum |
270 // smi, for which the negation is not a smi. | 270 // smi, for which the negation is not a smi. |
271 int digit = -(val.remainder(10)); | 271 int digit = -(val.remainder(10)); |
272 reversed[index++] = digit + 0x30; | 272 reversed[index++] = digit + 0x30; |
273 val = -(val ~/ 10); | 273 val = -(val ~/ 10); |
274 } | 274 } |
275 | 275 |
276 while (val > 0) { | 276 while (val > 0) { |
277 int digit = val % 10; | 277 int digit = val % 10; |
| 278 val = val ~/ 10; |
278 reversed[index++] = (digit + 0x30); | 279 reversed[index++] = (digit + 0x30); |
279 val = val ~/ 10; | |
280 } | 280 } |
281 if (negative) reversed[index++] = 0x2D; // '-'. | 281 if (negative) reversed[index++] = 0x2D; // '-'. |
282 | 282 |
283 _OneByteString string = _OneByteString._allocate(index); | 283 _OneByteString string = _OneByteString._allocate(index); |
284 for (int i = 0, j = index; i < index; i++) { | 284 for (int i = 0, j = index; i < index; i++) { |
285 string._setAt(i, reversed[--j]); | 285 string._setAt(i, reversed[--j]); |
286 } | 286 } |
287 return string; | 287 return string; |
288 } | 288 } |
289 } | 289 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 } else { | 334 } else { |
335 return 0; | 335 return 0; |
336 } | 336 } |
337 } | 337 } |
338 int _shlFromInt(int other) native "Bigint_shlFromInt"; | 338 int _shlFromInt(int other) native "Bigint_shlFromInt"; |
339 | 339 |
340 int pow(int exponent) { | 340 int pow(int exponent) { |
341 throw "Bigint.pow not implemented"; | 341 throw "Bigint.pow not implemented"; |
342 } | 342 } |
343 } | 343 } |
OLD | NEW |