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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 * Returns "-0.0" for negative zero. | 126 * Returns "-0.0" for negative zero. |
127 * | 127 * |
128 * It should always be the case that if [:d:] is a [double], then | 128 * It should always be the case that if [:d:] is a [double], then |
129 * [:d == double.parse(d.toString()):]. | 129 * [:d == double.parse(d.toString()):]. |
130 */ | 130 */ |
131 String toString(); | 131 String toString(); |
132 | 132 |
133 /** | 133 /** |
134 * Parse [source] as an double literal and return its value. | 134 * Parse [source] as an double literal and return its value. |
135 * | 135 * |
136 * Accepts the same format as double literals: | 136 * Accepts the following format: |
137 * [: ['+'|'-'] [digit* '.'] digit+ [('e'|'E') ['+'|'-'] digit+] :] | 137 * `/^\s*[+-]?(?:Infinity|NaN|(?:\.\d+|\d+(?:\.\d*)?)(?:[eE][+-]?\d+)?)\s*$`. |
Lasse Reichstein Nielsen
2013/05/21 06:12:09
Don't use RegExp as specification. It's unreadable
floitsch
2013/05/21 14:39:31
Removed the regexp.
As discussed keeping the new b
| |
138 * | 138 * |
139 * Also recognizes "NaN", "Infinity" and "-Infinity" as inputs and | 139 * In English this equals an optional sign followed by either, "Infinity", |
140 * returns the corresponding double value. | 140 * "NaN" or a double number. A double number is composed of the mantissa and |
Lasse Reichstein Nielsen
2013/05/21 06:12:09
This accepts -NaN, which is meaningless. Please av
floitsch
2013/05/21 14:39:31
As discussed. keeping.
| |
141 * and optional exponent part. The mantissa is either a dot followed by a | |
142 * sequence of digits, or a sequence of digits optionally followed by a dot | |
143 * and more digits. The (optional) exponent part consists of the character | |
144 * "e" or "E", an optional sign, and the exponent digits. | |
141 * | 145 * |
142 * If the [soure] is not a valid double literal, the [handleError] | 146 * The whole double may be surrounded by whitespace. |
147 * | |
148 * If the [source] is not a valid double literal, the [handleError] | |
143 * is called with the [source] as argument, and its return value is | 149 * is called with the [source] as argument, and its return value is |
144 * used instead. If no handleError is provided, a [FormatException] | 150 * used instead. If no handleError is provided, a [FormatException] |
145 * is thrown. | 151 * is thrown. |
152 * | |
153 * Examples of accepted strings: | |
154 * | |
155 * "3.14" | |
156 * " 3.14 \xA0" | |
157 * "0." | |
158 * ".0" | |
159 * "-1.e3" | |
160 * "1234E+7" | |
161 * "+.12e-9" | |
162 * "-NaN" | |
146 */ | 163 */ |
147 external static double parse(String source, | 164 external static double parse(String source, |
148 [double handleError(String source)]); | 165 [double handleError(String source)]); |
149 } | 166 } |
OLD | NEW |