| 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 // Dart core library. | 4 // Dart core library. |
| 5 | 5 |
| 6 // VM implementation of double. | 6 // VM implementation of double. |
| 7 | 7 |
| 8 patch class double { | 8 patch class double { |
| 9 | 9 |
| 10 static double _nativeParse(String str, | 10 static double _nativeParse(String str, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 10000000000000000000.0, | 105 10000000000000000000.0, |
| 106 100000000000000000000.0, /* 20 */ | 106 100000000000000000000.0, /* 20 */ |
| 107 1000000000000000000000.0, | 107 1000000000000000000000.0, |
| 108 10000000000000000000000.0, | 108 10000000000000000000000.0, |
| 109 ]; | 109 ]; |
| 110 if (exponent < 0) { | 110 if (exponent < 0) { |
| 111 int negExponent = -exponent; | 111 int negExponent = -exponent; |
| 112 if (negExponent >= P10.length) return null; | 112 if (negExponent >= P10.length) return null; |
| 113 return sign * (doubleValue / P10[negExponent]); | 113 return sign * (doubleValue / P10[negExponent]); |
| 114 } | 114 } |
| 115 if (exponent > P10.length) return null; | 115 if (exponent >= P10.length) return null; |
| 116 return sign * (doubleValue * P10[exponent]); | 116 return sign * (doubleValue * P10[exponent]); |
| 117 } | 117 } |
| 118 | 118 |
| 119 static double _parse(var str) { | 119 static double _parse(var str) { |
| 120 int len = str.length; | 120 int len = str.length; |
| 121 int start = str._firstNonWhitespace(); | 121 int start = str._firstNonWhitespace(); |
| 122 if (start == len) return null; // All whitespace. | 122 if (start == len) return null; // All whitespace. |
| 123 int end = str._lastNonWhitespace() + 1; | 123 int end = str._lastNonWhitespace() + 1; |
| 124 assert(start < end); | 124 assert(start < end); |
| 125 var result = _tryParseDouble(str, start, end); | 125 var result = _tryParseDouble(str, start, end); |
| 126 if (result != null) return result; | 126 if (result != null) return result; |
| 127 return _nativeParse(str, start, end); | 127 return _nativeParse(str, start, end); |
| 128 } | 128 } |
| 129 | 129 |
| 130 /* patch */ static double parse(String str, | 130 /* patch */ static double parse(String str, |
| 131 [double onError(String str)]) { | 131 [double onError(String str)]) { |
| 132 var result = _parse(str); | 132 var result = _parse(str); |
| 133 if (result == null) { | 133 if (result == null) { |
| 134 if (onError == null) throw new FormatException("Invalid double", str); | 134 if (onError == null) throw new FormatException("Invalid double", str); |
| 135 return onError(str); | 135 return onError(str); |
| 136 } | 136 } |
| 137 return result; | 137 return result; |
| 138 } | 138 } |
| 139 } | 139 } |
| OLD | NEW |