| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // The value of binary number weights each bit by a power of two. The | 110 // The value of binary number weights each bit by a power of two. The |
| 111 // twos-complement value weights the sign bit negatively. We compute the | 111 // twos-complement value weights the sign bit negatively. We compute the |
| 112 // value of the negative weighting by isolating the sign bit with the | 112 // value of the negative weighting by isolating the sign bit with the |
| 113 // correct power of two weighting and subtracting it from the value of the | 113 // correct power of two weighting and subtracting it from the value of the |
| 114 // lower bits. | 114 // lower bits. |
| 115 int signMask = 1 << (width - 1); | 115 int signMask = 1 << (width - 1); |
| 116 return (this & (signMask - 1)) - (this & signMask); | 116 return (this & (signMask - 1)) - (this & signMask); |
| 117 } | 117 } |
| 118 | 118 |
| 119 int compareTo(num other) { | 119 int compareTo(num other) { |
| 120 final int EQUAL = 0, LESS = -1, GREATER = 1; | 120 const int EQUAL = 0, LESS = -1, GREATER = 1; |
| 121 if (other is double) { | 121 if (other is double) { |
| 122 // TODO(floitsch): the following locals should be 'const'. | 122 const int MAX_EXACT_INT_TO_DOUBLE = 9007199254740992; // 2^53. |
| 123 int MAX_EXACT_INT_TO_DOUBLE = 9007199254740992; // 2^53. | 123 const int MIN_EXACT_INT_TO_DOUBLE = -MAX_EXACT_INT_TO_DOUBLE; |
| 124 int MIN_EXACT_INT_TO_DOUBLE = -MAX_EXACT_INT_TO_DOUBLE; | |
| 125 double d = other; | 124 double d = other; |
| 126 if (d.isInfinite) { | 125 if (d.isInfinite) { |
| 127 return d == double.NEGATIVE_INFINITY ? GREATER : LESS; | 126 return d == double.NEGATIVE_INFINITY ? GREATER : LESS; |
| 128 } | 127 } |
| 129 if (d.isNaN) { | 128 if (d.isNaN) { |
| 130 return LESS; | 129 return LESS; |
| 131 } | 130 } |
| 132 if (MIN_EXACT_INT_TO_DOUBLE <= this && this <= MAX_EXACT_INT_TO_DOUBLE) { | 131 if (MIN_EXACT_INT_TO_DOUBLE <= this && this <= MAX_EXACT_INT_TO_DOUBLE) { |
| 133 // Let the double implementation deal with -0.0. | 132 // Let the double implementation deal with -0.0. |
| 134 return -(d.compareTo(this.toDouble())); | 133 return -(d.compareTo(this.toDouble())); |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } else { | 467 } else { |
| 469 return 0; | 468 return 0; |
| 470 } | 469 } |
| 471 } | 470 } |
| 472 int _shlFromInt(int other) native "Bigint_shlFromInt"; | 471 int _shlFromInt(int other) native "Bigint_shlFromInt"; |
| 473 | 472 |
| 474 int pow(int exponent) { | 473 int pow(int exponent) { |
| 475 throw "Bigint.pow not implemented"; | 474 throw "Bigint.pow not implemented"; |
| 476 } | 475 } |
| 477 } | 476 } |
| OLD | NEW |