| 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 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 get hashCode { | 8 int get hashCode { |
| 9 if (isNaN || isInfinite) return 0; | 9 if (isNaN || isInfinite) return 0; |
| 10 return toInt(); | 10 return toInt(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 bool get isNegative native "Double_getIsNegative"; | 93 bool get isNegative native "Double_getIsNegative"; |
| 94 bool get isInfinite native "Double_getIsInfinite"; | 94 bool get isInfinite native "Double_getIsInfinite"; |
| 95 bool get isNaN native "Double_getIsNaN"; | 95 bool get isNaN native "Double_getIsNaN"; |
| 96 | 96 |
| 97 double abs() { | 97 double abs() { |
| 98 // Handle negative 0.0. | 98 // Handle negative 0.0. |
| 99 if (this == 0.0) return 0.0; | 99 if (this == 0.0) return 0.0; |
| 100 return this < 0.0 ? -this : this; | 100 return this < 0.0 ? -this : this; |
| 101 } | 101 } |
| 102 | 102 |
| 103 double round() native "Double_round"; | 103 int round() => roundToDouble().toInt(); |
| 104 double floor() native "Double_floor"; | 104 int floor() => floorToDouble().toInt(); |
| 105 double ceil () native "Double_ceil"; | 105 int ceil () => ceilToDouble().toInt(); |
| 106 double truncate() native "Double_truncate"; | 106 int truncate() => truncateToDouble().toInt(); |
| 107 |
| 108 double roundToDouble() native "Double_round"; |
| 109 double floorToDouble() native "Double_floor"; |
| 110 double ceilToDouble() native "Double_ceil"; |
| 111 double truncateToDouble() native "Double_truncate"; |
| 107 | 112 |
| 108 num clamp(num lowerLimit, num upperLimit) { | 113 num clamp(num lowerLimit, num upperLimit) { |
| 109 if (lowerLimit is! num) throw new ArgumentError(lowerLimit); | 114 if (lowerLimit is! num) throw new ArgumentError(lowerLimit); |
| 110 if (upperLimit is! num) throw new ArgumentError(upperLimit); | 115 if (upperLimit is! num) throw new ArgumentError(upperLimit); |
| 111 | 116 |
| 112 if (lowerLimit.compareTo(upperLimit) > 0) { | 117 if (lowerLimit.compareTo(upperLimit) > 0) { |
| 113 throw new ArgumentError(lowerLimit); | 118 throw new ArgumentError(lowerLimit); |
| 114 } | 119 } |
| 115 if (lowerLimit.isNaN) return lowerLimit; | 120 if (lowerLimit.isNaN) return lowerLimit; |
| 116 if (this.compareTo(lowerLimit) < 0) return lowerLimit; | 121 if (this.compareTo(lowerLimit) < 0) return lowerLimit; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 return EQUAL; | 241 return EQUAL; |
| 237 } | 242 } |
| 238 } else if (isNaN) { | 243 } else if (isNaN) { |
| 239 return other.isNaN ? EQUAL : GREATER; | 244 return other.isNaN ? EQUAL : GREATER; |
| 240 } else { | 245 } else { |
| 241 // Other is NaN. | 246 // Other is NaN. |
| 242 return LESS; | 247 return LESS; |
| 243 } | 248 } |
| 244 } | 249 } |
| 245 } | 250 } |
| OLD | NEW |