40
40
*/
41
41
package com .oracle .graal .python .builtins .objects .floats ;
42
42
43
+ import java .math .BigDecimal ;
44
+
43
45
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
44
46
import com .oracle .truffle .api .CompilerDirectives .ValueType ;
45
47
@@ -66,7 +68,7 @@ private static boolean isAsciiSpace(char c) {
66
68
* followed by a digit and removes them. Does not create a copy if the original String does not
67
69
* need any cleanup. Combines _PyUnicode_TransformDecimalAndSpaceToASCII and
68
70
* _Py_string_to_number_with_underscores.
69
- *
71
+ *
70
72
* @param src the String to transform
71
73
* @return the transformed String, {@code src} if the input does not need cleanup or
72
74
* {@code null} if there are invalid underscores or unicode characters other than
@@ -145,7 +147,7 @@ public StringToDoubleResult(double value, int position) {
145
147
* </ul>
146
148
* Implements PyOS_string_to_double and _PyOS_ascii_strtod except error handling and handling of
147
149
* locale-specific decimal point.
148
- *
150
+ *
149
151
* @param str the string to parse
150
152
* @param start starting position in the string
151
153
* @param len length of the string
@@ -217,9 +219,15 @@ public static StringToDoubleResult stringToDouble(String str, int start, int len
217
219
return null ;
218
220
}
219
221
try {
220
- return new StringToDoubleResult (Double .parseDouble (str .substring (start , i )), i );
222
+ String substr = str .substring (start , i );
223
+ double d = Double .parseDouble (substr );
224
+ if (!Double .isFinite (d )) {
225
+ d = new BigDecimal (substr ).doubleValue ();
226
+ }
227
+ return new StringToDoubleResult (d , i );
221
228
} catch (NumberFormatException e ) {
222
- // Should not happen since the input to Double.parseDouble should be correct
229
+ // Should not happen since the input to Double.parseDouble() / BigDecimal(String) should
230
+ // be correct
223
231
return null ;
224
232
}
225
233
}
0 commit comments