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 class _Double extends _Num implements double { | 5 class _Double extends _Num implements double { |
6 factory _Double.fromInteger(int value) | 6 factory _Double.fromInteger(int value) |
7 native "Double_doubleFromInteger"; | 7 native "Double_doubleFromInteger"; |
8 | 8 |
9 Type get runtimeType => double; | 9 Type get runtimeType => double; |
10 | 10 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 if (this == double.INFINITY) return "Infinity"; | 239 if (this == double.INFINITY) return "Infinity"; |
240 if (this == -double.INFINITY) return "-Infinity"; | 240 if (this == -double.INFINITY) return "-Infinity"; |
241 | 241 |
242 return _toStringAsPrecision(precision); | 242 return _toStringAsPrecision(precision); |
243 } | 243 } |
244 String _toStringAsPrecision(int fractionDigits) | 244 String _toStringAsPrecision(int fractionDigits) |
245 native "Double_toStringAsPrecision"; | 245 native "Double_toStringAsPrecision"; |
246 | 246 |
247 // Order is: NaN > Infinity > ... > 0.0 > -0.0 > ... > -Infinity. | 247 // Order is: NaN > Infinity > ... > 0.0 > -0.0 > ... > -Infinity. |
248 int compareTo(num other) { | 248 int compareTo(num other) { |
249 final int EQUAL = 0, LESS = -1, GREATER = 1; | 249 const int EQUAL = 0, LESS = -1, GREATER = 1; |
250 if (this < other) { | 250 if (this < other) { |
251 return LESS; | 251 return LESS; |
252 } else if (this > other) { | 252 } else if (this > other) { |
253 return GREATER; | 253 return GREATER; |
254 } else if (this == other) { | 254 } else if (this == other) { |
255 if (this == 0.0) { | 255 if (this == 0.0) { |
256 bool thisIsNegative = isNegative; | 256 bool thisIsNegative = isNegative; |
257 bool otherIsNegative = other.isNegative; | 257 bool otherIsNegative = other.isNegative; |
258 if (thisIsNegative == otherIsNegative) { | 258 if (thisIsNegative == otherIsNegative) { |
259 return EQUAL; | 259 return EQUAL; |
260 } | 260 } |
261 return thisIsNegative ? LESS : GREATER; | 261 return thisIsNegative ? LESS : GREATER; |
262 } else { | 262 } else { |
263 return EQUAL; | 263 return EQUAL; |
264 } | 264 } |
265 } else if (isNaN) { | 265 } else if (isNaN) { |
266 return other.isNaN ? EQUAL : GREATER; | 266 return other.isNaN ? EQUAL : GREATER; |
267 } else { | 267 } else { |
268 // Other is NaN. | 268 // Other is NaN. |
269 return LESS; | 269 return LESS; |
270 } | 270 } |
271 } | 271 } |
272 } | 272 } |
OLD | NEW |