| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (lowerLimit.isNaN) return lowerLimit; | 156 if (lowerLimit.isNaN) return lowerLimit; |
| 157 // Note that we don't need to care for -0.0 for the lower limit. | 157 // Note that we don't need to care for -0.0 for the lower limit. |
| 158 if (this < lowerLimit) return lowerLimit; | 158 if (this < lowerLimit) return lowerLimit; |
| 159 if (this.compareTo(upperLimit) > 0) return upperLimit; | 159 if (this.compareTo(upperLimit) > 0) return upperLimit; |
| 160 return this; | 160 return this; |
| 161 } | 161 } |
| 162 | 162 |
| 163 int toInt() { return this; } | 163 int toInt() { return this; } |
| 164 double toDouble() { return new _Double.fromInteger(this); } | 164 double toDouble() { return new _Double.fromInteger(this); } |
| 165 | 165 |
| 166 int pow(int exponent) { | |
| 167 // Exponentiation by squaring. | |
| 168 int base = this; | |
| 169 int result = 1; | |
| 170 while (exponent != 0) { | |
| 171 if ((exponent & 1) == 1) { | |
| 172 result *= base; | |
| 173 } | |
| 174 exponent >>= 1; | |
| 175 // Skip unnecessary operation (can overflow to Mint or Bigint). | |
| 176 if (exponent != 0) { | |
| 177 base *= base; | |
| 178 } | |
| 179 } | |
| 180 return result; | |
| 181 } | |
| 182 | |
| 183 String toStringAsFixed(int fractionDigits) { | 166 String toStringAsFixed(int fractionDigits) { |
| 184 return this.toDouble().toStringAsFixed(fractionDigits); | 167 return this.toDouble().toStringAsFixed(fractionDigits); |
| 185 } | 168 } |
| 186 String toStringAsExponential([int fractionDigits]) { | 169 String toStringAsExponential([int fractionDigits]) { |
| 187 return this.toDouble().toStringAsExponential(fractionDigits); | 170 return this.toDouble().toStringAsExponential(fractionDigits); |
| 188 } | 171 } |
| 189 String toStringAsPrecision(int precision) { | 172 String toStringAsPrecision(int precision) { |
| 190 return this.toDouble().toStringAsPrecision(precision); | 173 return this.toDouble().toStringAsPrecision(precision); |
| 191 } | 174 } |
| 192 | 175 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } else { | 283 } else { |
| 301 return 0; | 284 return 0; |
| 302 } | 285 } |
| 303 } | 286 } |
| 304 int _shlFromInt(int other) native "Bigint_shlFromInt"; | 287 int _shlFromInt(int other) native "Bigint_shlFromInt"; |
| 305 | 288 |
| 306 int pow(int exponent) { | 289 int pow(int exponent) { |
| 307 throw "Bigint.pow not implemented"; | 290 throw "Bigint.pow not implemented"; |
| 308 } | 291 } |
| 309 } | 292 } |
| OLD | NEW |