| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  107       } |  107       } | 
|  108       if (d.isNaN) { |  108       if (d.isNaN) { | 
|  109         return LESS; |  109         return LESS; | 
|  110       } |  110       } | 
|  111       if (MIN_EXACT_INT_TO_DOUBLE <= this && this <= MAX_EXACT_INT_TO_DOUBLE) { |  111       if (MIN_EXACT_INT_TO_DOUBLE <= this && this <= MAX_EXACT_INT_TO_DOUBLE) { | 
|  112         // Let the double implementation deal with -0.0. |  112         // Let the double implementation deal with -0.0. | 
|  113         return -(d.compareTo(this.toDouble())); |  113         return -(d.compareTo(this.toDouble())); | 
|  114       } else { |  114       } else { | 
|  115         // If abs(other) > MAX_EXACT_INT_TO_DOUBLE, then other has an integer |  115         // If abs(other) > MAX_EXACT_INT_TO_DOUBLE, then other has an integer | 
|  116         // value (no bits below the decimal point). |  116         // value (no bits below the decimal point). | 
|  117         other = d.toInt(); |  117         other = d.truncate(); | 
|  118       } |  118       } | 
|  119     } |  119     } | 
|  120     if (this < other) { |  120     if (this < other) { | 
|  121       return LESS; |  121       return LESS; | 
|  122     } else if (this > other) { |  122     } else if (this > other) { | 
|  123       return GREATER; |  123       return GREATER; | 
|  124     } else { |  124     } else { | 
|  125       return EQUAL; |  125       return EQUAL; | 
|  126     } |  126     } | 
|  127   } |  127   } | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|  148     if (lowerLimit.compareTo(upperLimit) > 0) { |  148     if (lowerLimit.compareTo(upperLimit) > 0) { | 
|  149       throw new ArgumentError(lowerLimit); |  149       throw new ArgumentError(lowerLimit); | 
|  150     } |  150     } | 
|  151     if (lowerLimit.isNaN) return lowerLimit; |  151     if (lowerLimit.isNaN) return lowerLimit; | 
|  152     // Note that we don't need to care for -0.0 for the lower limit. |  152     // Note that we don't need to care for -0.0 for the lower limit. | 
|  153     if (this < lowerLimit) return lowerLimit; |  153     if (this < lowerLimit) return lowerLimit; | 
|  154     if (this.compareTo(upperLimit) > 0) return upperLimit; |  154     if (this.compareTo(upperLimit) > 0) return upperLimit; | 
|  155     return this; |  155     return this; | 
|  156   } |  156   } | 
|  157  |  157  | 
|  158   int toInt() { return this; } |  | 
|  159   double toDouble() { return new _Double.fromInteger(this); } |  158   double toDouble() { return new _Double.fromInteger(this); } | 
|  160  |  159  | 
|  161   int pow(int exponent) { |  160   int pow(int exponent) { | 
|  162     double res = this.toDouble().pow(exponent); |  161     double res = this.toDouble().pow(exponent); | 
|  163     if (res.isInfinite) { |  162     if (res.isInfinite) { | 
|  164       // Use Bigint instead. |  163       // Use Bigint instead. | 
|  165       throw "_IntegerImplementation.pow not implemented for large integers."; |  164       throw "_IntegerImplementation.pow not implemented for large integers."; | 
|  166     } |  165     } | 
|  167     return res.toInt(); |  166     return res.truncate(); | 
|  168   } |  167   } | 
|  169  |  168  | 
|  170   String toStringAsFixed(int fractionDigits) { |  169   String toStringAsFixed(int fractionDigits) { | 
|  171     return this.toDouble().toStringAsFixed(fractionDigits); |  170     return this.toDouble().toStringAsFixed(fractionDigits); | 
|  172   } |  171   } | 
|  173   String toStringAsExponential([int fractionDigits]) { |  172   String toStringAsExponential([int fractionDigits]) { | 
|  174     return this.toDouble().toStringAsExponential(fractionDigits); |  173     return this.toDouble().toStringAsExponential(fractionDigits); | 
|  175   } |  174   } | 
|  176   String toStringAsPrecision(int precision) { |  175   String toStringAsPrecision(int precision) { | 
|  177     return this.toDouble().toStringAsPrecision(precision); |  176     return this.toDouble().toStringAsPrecision(precision); | 
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  263     } |  262     } | 
|  264   } |  263   } | 
|  265   int _shlFromInt(int other) { |  264   int _shlFromInt(int other) { | 
|  266     throw const OutOfMemoryError(); |  265     throw const OutOfMemoryError(); | 
|  267   } |  266   } | 
|  268  |  267  | 
|  269   int pow(int exponent) { |  268   int pow(int exponent) { | 
|  270     throw "Bigint.pow not implemented"; |  269     throw "Bigint.pow not implemented"; | 
|  271   } |  270   } | 
|  272 } |  271 } | 
| OLD | NEW |