| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 num operator +(num other) { | 8 num operator +(num other) { |
| 9 return other.addFromInteger(this); | 9 return other.addFromInteger(this); |
| 10 } | 10 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 int abs() { | 85 int abs() { |
| 86 return this < 0 ? -this : this; | 86 return this < 0 ? -this : this; |
| 87 } | 87 } |
| 88 bool isEven() { return ((this & 1) === 0); } | 88 bool isEven() { return ((this & 1) === 0); } |
| 89 bool isOdd() { return !isEven(); } | 89 bool isOdd() { return !isEven(); } |
| 90 bool isNaN() { return false; } | 90 bool isNaN() { return false; } |
| 91 bool isNegative() { return this < 0; } | 91 bool isNegative() { return this < 0; } |
| 92 bool isInfinite() { return false; } | 92 bool isInfinite() { return false; } |
| 93 | 93 |
| 94 int compareTo(Comparable other) { | 94 int compareTo(Comparable other) { |
| 95 if (this == other) return 0; | 95 final int EQUAL = 0, LESS = -1, GREATER = 1; |
| 96 if (this < other) return -1; | 96 if (this < other) { |
| 97 return 1; | 97 return LESS; |
| 98 } else if (this > other) { |
| 99 return GREATER; |
| 100 } else if (this == other) { |
| 101 return EQUAL; |
| 102 } else { |
| 103 // Other is NaN. |
| 104 return LESS; |
| 105 } |
| 98 } | 106 } |
| 107 |
| 99 int round() { return this; } | 108 int round() { return this; } |
| 100 int floor() { return this; } | 109 int floor() { return this; } |
| 101 int ceil() { return this; } | 110 int ceil() { return this; } |
| 102 int truncate() { return this; } | 111 int truncate() { return this; } |
| 103 | 112 |
| 104 int toInt() { return this; } | 113 int toInt() { return this; } |
| 105 double toDouble() { return new Double.fromInteger(this); } | 114 double toDouble() { return new Double.fromInteger(this); } |
| 106 | 115 |
| 107 int pow(int exponent) { | 116 int pow(int exponent) { |
| 108 throw "IntegerImplementation.pow not implemented"; | 117 throw "IntegerImplementation.pow not implemented"; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 if (other < 0) { | 182 if (other < 0) { |
| 174 return -1; | 183 return -1; |
| 175 } else { | 184 } else { |
| 176 return 0; | 185 return 0; |
| 177 } | 186 } |
| 178 } | 187 } |
| 179 int shlFromInt(int other) { | 188 int shlFromInt(int other) { |
| 180 throw const OutOfMemoryException(); | 189 throw const OutOfMemoryException(); |
| 181 } | 190 } |
| 182 } | 191 } |
| OLD | NEW |