| 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 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 // TODO: Convert this abstract class into a concrete class double | 7 // TODO: Convert this abstract class into a concrete class double |
| 8 // that uses the patch class functionality to account for the | 8 // that uses the patch class functionality to account for the |
| 9 // different platform implementations. | 9 // different platform implementations. |
| 10 | 10 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 * Returns "NaN" for the Not-a-Number value. | 160 * Returns "NaN" for the Not-a-Number value. |
| 161 * Returns "Infinity" and "-Infinity" for positive and negative Infinity. | 161 * Returns "Infinity" and "-Infinity" for positive and negative Infinity. |
| 162 * Returns "-0.0" for negative zero. | 162 * Returns "-0.0" for negative zero. |
| 163 * | 163 * |
| 164 * For all doubles, `d`, converting to a string and parsing the string back | 164 * For all doubles, `d`, converting to a string and parsing the string back |
| 165 * gives the same value again: `d == double.parse(d.toString())` (except when | 165 * gives the same value again: `d == double.parse(d.toString())` (except when |
| 166 * `d` is NaN). | 166 * `d` is NaN). |
| 167 */ | 167 */ |
| 168 String toString(); | 168 String toString(); |
| 169 | 169 |
| 170 @patch | 170 /** |
| 171 * Parse [source] as an double literal and return its value. |
| 172 * |
| 173 * Accepts an optional sign (`+` or `-`) followed by either the characters |
| 174 * "Infinity", the characters "NaN" or a floating-point representation. |
| 175 * A floating-point representation is composed of a mantissa and an optional |
| 176 * exponent part. The mantissa is either a decimal point (`.`) followed by a |
| 177 * sequence of (decimal) digits, or a sequence of digits |
| 178 * optionally followed by a decimal point and optionally more digits. The |
| 179 * (optional) exponent part consists of the character "e" or "E", an optional |
| 180 * sign, and one or more digits. |
| 181 * |
| 182 * Leading and trailing whitespace is ignored. |
| 183 * |
| 184 * If the [source] is not a valid double literal, the [onError] |
| 185 * is called with the [source] as argument, and its return value is |
| 186 * used instead. If no `onError` is provided, a [FormatException] |
| 187 * is thrown instead. |
| 188 * |
| 189 * The [onError] function is only invoked if [source] is a [String] with an |
| 190 * invalid format. It is not invoked if the [source] is invalid for some |
| 191 * other reason, for example by being `null`. |
| 192 * |
| 193 * Examples of accepted strings: |
| 194 * |
| 195 * "3.14" |
| 196 * " 3.14 \xA0" |
| 197 * "0." |
| 198 * ".0" |
| 199 * "-1.e3" |
| 200 * "1234E+7" |
| 201 * "+.12e-9" |
| 202 * "-NaN" |
| 203 */ |
| 171 static double parse(String source, | 204 static double parse(String source, |
| 172 [double onError(String source)]) { | 205 [double onError(String source)]) { |
| 173 return Primitives.parseDouble(source, onError); | 206 return Primitives.parseDouble(source, onError); |
| 174 } | 207 } |
| 175 } | 208 } |
| OLD | NEW |