| 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 class Double implements double { | 5 class Double implements double { |
| 6 factory Double.fromInteger(int value) | 6 factory Double.fromInteger(int value) |
| 7 native "Double_doubleFromInteger"; | 7 native "Double_doubleFromInteger"; |
| 8 int hashCode() { | 8 int hashCode() { |
| 9 try { | 9 try { |
| 10 return toInt(); | 10 return toInt(); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 if (isNaN()) return "NaN"; | 193 if (isNaN()) return "NaN"; |
| 194 if (this == double.INFINITY) return "Infinity"; | 194 if (this == double.INFINITY) return "Infinity"; |
| 195 if (this == -double.INFINITY) return "-Infinity"; | 195 if (this == -double.INFINITY) return "-Infinity"; |
| 196 | 196 |
| 197 return _toStringAsPrecision(precision); | 197 return _toStringAsPrecision(precision); |
| 198 } | 198 } |
| 199 String _toStringAsPrecision(int fractionDigits) | 199 String _toStringAsPrecision(int fractionDigits) |
| 200 native "Double_toStringAsPrecision"; | 200 native "Double_toStringAsPrecision"; |
| 201 | 201 |
| 202 String toRadixString(int radix) { | 202 String toRadixString(int radix) { |
| 203 throw "Double.toRadixString unimplemented."; | 203 return toInt().toRadixString(radix); |
| 204 } | 204 } |
| 205 | 205 |
| 206 // Order is: NaN > Infinity > ... > 0.0 > -0.0 > ... > -Infinity. | 206 // Order is: NaN > Infinity > ... > 0.0 > -0.0 > ... > -Infinity. |
| 207 int compareTo(Comparable other) { | 207 int compareTo(Comparable other) { |
| 208 final int EQUAL = 0, LESS = -1, GREATER = 1; | 208 final int EQUAL = 0, LESS = -1, GREATER = 1; |
| 209 if (this < other) { | 209 if (this < other) { |
| 210 return LESS; | 210 return LESS; |
| 211 } else if (this > other) { | 211 } else if (this > other) { |
| 212 return GREATER; | 212 return GREATER; |
| 213 } else if (this == other) { | 213 } else if (this == other) { |
| 214 if (this == 0.0) { | 214 if (this == 0.0) { |
| 215 bool thisIsNegative = isNegative(); | 215 bool thisIsNegative = isNegative(); |
| 216 bool otherIsNegative = other.isNegative(); | 216 bool otherIsNegative = other.isNegative(); |
| 217 if (thisIsNegative == otherIsNegative) { | 217 if (thisIsNegative == otherIsNegative) { |
| 218 return EQUAL; | 218 return EQUAL; |
| 219 } | 219 } |
| 220 return thisIsNegative ? LESS : GREATER; | 220 return thisIsNegative ? LESS : GREATER; |
| 221 } else { | 221 } else { |
| 222 return EQUAL; | 222 return EQUAL; |
| 223 } | 223 } |
| 224 } else if (isNaN()) { | 224 } else if (isNaN()) { |
| 225 return other.isNaN() ? EQUAL : GREATER; | 225 return other.isNaN() ? EQUAL : GREATER; |
| 226 } else { | 226 } else { |
| 227 // Other is NaN. | 227 // Other is NaN. |
| 228 return LESS; | 228 return LESS; |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 } | 231 } |
| OLD | NEW |