Skip to content

Commit 6d2b16c

Browse files
committed
Support short float_repr_style
1 parent 2319c0d commit 6d2b16c

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,8 +1024,10 @@ private double convertStringToDouble(String str) {
10241024
try {
10251025
// Double.valueOf allows format specifier ("d" or "f") at the end
10261026
String lowSval = sval.toLowerCase(Locale.ENGLISH);
1027-
if (lowSval.equals("nan") || lowSval.equals("+nan") || lowSval.equals("-nan")) {
1027+
if (lowSval.equals("nan") || lowSval.equals("+nan")) {
10281028
return Double.NaN;
1029+
} else if (lowSval.equals("-nan")) {
1030+
return Math.copySign(Double.NaN, -1);
10291031
} else if (lowSval.equals("inf") || lowSval.equals("+inf") || lowSval.equals("infinity") || lowSval.equals("+infinity")) {
10301032
return Double.POSITIVE_INFINITY;
10311033
} else if (lowSval.equals("-inf") || lowSval.equals("-infinity")) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,8 @@ private static double op(double x, long n) {
941941
return Math.copySign(0.0, x);
942942
} else {
943943
// We have to work it out properly.
944-
BigDecimal xx = BigDecimal.valueOf(x);
945-
BigDecimal rr = xx.setScale((int) n, RoundingMode.HALF_UP);
944+
BigDecimal xx = new BigDecimal(x);
945+
BigDecimal rr = xx.setScale((int) n, RoundingMode.HALF_EVEN);
946946
return rr.doubleValue();
947947
}
948948
}

graalpython/lib-graalpython/sys.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def make_float_info_class():
104104
float_info = make_float_info_class()(float_info)
105105
del make_float_info_class
106106

107+
float_repr_style = 'short'
108+
107109
def make_int_info_class():
108110
from _descriptor import make_named_tuple_class
109111
return make_named_tuple_class(

0 commit comments

Comments
 (0)