| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 String _toStringAsFixed(int fractionDigits) native "Double_toStringAsFixed"; | 143 String _toStringAsFixed(int fractionDigits) native "Double_toStringAsFixed"; |
| 144 | 144 |
| 145 String toStringAsExponential(int fractionDigits) { | 145 String toStringAsExponential(int fractionDigits) { |
| 146 // See ECMAScript-262, 15.7.4.6 for details. | 146 // See ECMAScript-262, 15.7.4.6 for details. |
| 147 | 147 |
| 148 // The EcmaScript specification checks for NaN and Infinity before looking | 148 // The EcmaScript specification checks for NaN and Infinity before looking |
| 149 // at the fractionDigits. In Dart we are consistent with toStringAsFixed and | 149 // at the fractionDigits. In Dart we are consistent with toStringAsFixed and |
| 150 // look at the fractionDigits first. | 150 // look at the fractionDigits first. |
| 151 | 151 |
| 152 // Step 7. | 152 // Step 7. |
| 153 if (fractionDigits < 0 || fractionDigits > 20) { | 153 if (fractionDigits !== null && |
| 154 (fractionDigits < 0 || fractionDigits > 20)) { |
| 154 // TODO(antonm): should be proper RangeError or Dart counterpart. | 155 // TODO(antonm): should be proper RangeError or Dart counterpart. |
| 155 throw "Range error"; | 156 throw "Range error"; |
| 156 } | 157 } |
| 157 | 158 |
| 159 if (isNaN()) return "NaN"; |
| 160 if (this == double.INFINITY) return "Infinity"; |
| 161 if (this == -double.INFINITY) return "-Infinity"; |
| 162 |
| 163 // The dart function prints the shortest representation when fractionDigits |
| 164 // equals null. The native function wants -1 instead. |
| 165 fractionDigits = (fractionDigits === null) ? -1 : fractionDigits; |
| 166 |
| 158 return _toStringAsExponential(fractionDigits); | 167 return _toStringAsExponential(fractionDigits); |
| 159 } | 168 } |
| 160 String _toStringAsExponential(int fractionDigits) | 169 String _toStringAsExponential(int fractionDigits) |
| 161 native "Double_toStringAsExponential"; | 170 native "Double_toStringAsExponential"; |
| 162 | 171 |
| 163 String toStringAsPrecision(int precision) { | 172 String toStringAsPrecision(int precision) { |
| 164 // See ECMAScript-262, 15.7.4.7 for details. | 173 // See ECMAScript-262, 15.7.4.7 for details. |
| 165 | 174 |
| 166 // The EcmaScript specification checks for NaN and Infinity before looking | 175 // The EcmaScript specification checks for NaN and Infinity before looking |
| 167 // at the fractionDigits. In Dart we are consistent with toStringAsFixed and | 176 // at the fractionDigits. In Dart we are consistent with toStringAsFixed and |
| 168 // look at the fractionDigits first. | 177 // look at the fractionDigits first. |
| 169 | 178 |
| 170 // Step 8. | 179 // Step 8. |
| 171 if (precision < 1 || precision > 21) { | 180 if (precision < 1 || precision > 21) { |
| 172 // TODO(antonm): should be proper RangeError or Dart counterpart. | 181 // TODO(antonm): should be proper RangeError or Dart counterpart. |
| 173 throw "Range error"; | 182 throw "Range error"; |
| 174 } | 183 } |
| 175 | 184 |
| 185 if (isNaN()) return "NaN"; |
| 186 if (this == double.INFINITY) return "Infinity"; |
| 187 if (this == -double.INFINITY) return "-Infinity"; |
| 188 |
| 176 return _toStringAsPrecision(precision); | 189 return _toStringAsPrecision(precision); |
| 177 } | 190 } |
| 178 String _toStringAsPrecision(int fractionDigits) | 191 String _toStringAsPrecision(int fractionDigits) |
| 179 native "Double_toStringAsPrecision"; | 192 native "Double_toStringAsPrecision"; |
| 180 | 193 |
| 181 String toRadixString(int radix) { | 194 String toRadixString(int radix) { |
| 182 throw "Double.toRadixString unimplemented."; | 195 throw "Double.toRadixString unimplemented."; |
| 183 } | 196 } |
| 184 | 197 |
| 185 // Order is: NaN > Infinity > ... > 0.0 > -0.0 > ... > -Infinity. | 198 // Order is: NaN > Infinity > ... > 0.0 > -0.0 > ... > -Infinity. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 201 return EQUAL; | 214 return EQUAL; |
| 202 } | 215 } |
| 203 } else if (isNaN()) { | 216 } else if (isNaN()) { |
| 204 return other.isNaN() ? EQUAL : GREATER; | 217 return other.isNaN() ? EQUAL : GREATER; |
| 205 } else { | 218 } else { |
| 206 // Other is NaN. | 219 // Other is NaN. |
| 207 return LESS; | 220 return LESS; |
| 208 } | 221 } |
| 209 } | 222 } |
| 210 } | 223 } |
| OLD | NEW |