Skip to content

Commit 7a6281e

Browse files
committed
Make test_strtod pass
1 parent 469090a commit 7a6281e

File tree

2 files changed

+10
-2
lines changed
  • graalpython
    • com.oracle.graal.python.test/src/tests/unittest_tags
    • com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats

2 files changed

+10
-2
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_strtod.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*graalpython.lib-python.3.test.test_strtod.StrtodTests.test_bigcomp
22
*graalpython.lib-python.3.test.test_strtod.StrtodTests.test_boundaries
33
*graalpython.lib-python.3.test.test_strtod.StrtodTests.test_halfway_cases
4+
*graalpython.lib-python.3.test.test_strtod.StrtodTests.test_large_exponents
45
*graalpython.lib-python.3.test.test_strtod.StrtodTests.test_oversized_digit_strings
56
*graalpython.lib-python.3.test.test_strtod.StrtodTests.test_parsing
67
*graalpython.lib-python.3.test.test_strtod.StrtodTests.test_particular

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatUtils.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
*/
4141
package com.oracle.graal.python.builtins.objects.floats;
4242

43+
import java.math.BigDecimal;
44+
4345
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4446
import com.oracle.truffle.api.CompilerDirectives.ValueType;
4547

@@ -217,9 +219,14 @@ public static StringToDoubleResult stringToDouble(String str, int start, int len
217219
return null;
218220
}
219221
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);
221228
} 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 be correct
223230
return null;
224231
}
225232
}

0 commit comments

Comments
 (0)