Commit 407b2f95 authored by Boxiang Sun's avatar Boxiang Sun

add float_repr_style to sys module and enable test_strtod

parent e912efed
......@@ -458,3 +458,28 @@ typedef PY_LONG_LONG Py_intptr_t;
else if (errno == ERANGE) \
errno = 0; \
} while(0)
/* If we can't guarantee 53-bit precision, don't use the code
in Python/dtoa.c, but fall back to standard code. This
means that repr of a float will be long (17 sig digits).
Realistically, there are two things that could go wrong:
(1) doubles aren't IEEE 754 doubles, or
(2) we're on x86 with the rounding precision set to 64-bits
(extended precision), and we don't know how to change
the rounding precision.
*/
#if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \
!defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \
!defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)
#define PY_NO_SHORT_FLOAT_REPR
#endif
/* double rounding is symptomatic of use of extended precision on x86. If
we're seeing double rounding, and we don't have any mechanism available for
changing the FPU rounding precision, then don't use Python/dtoa.c. */
#if defined(X87_DOUBLE_ROUNDING) && !defined(HAVE_PY_SET_53BIT_PRECISION)
#define PY_NO_SHORT_FLOAT_REPR
#endif
# expected: fail
# Tests for the correctly-rounded string -> float conversions
# introduced in Python 2.7 and 3.1.
......
......@@ -721,6 +721,14 @@ void setupSys() {
#ifdef Py_USING_UNICODE
SET_SYS_FROM_STRING("maxunicode", PyInt_FromLong(PyUnicode_GetMax()));
#endif
/* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */
#ifndef PY_NO_SHORT_FLOAT_REPR
SET_SYS_FROM_STRING("float_repr_style", PyString_FromString("short"));
#else
SET_SYS_FROM_STRING("float_repr_style", PyString_FromString("legacy"));
#endif
sys_flags_cls->tp_mro = BoxedTuple::create({ sys_flags_cls, object_cls });
sys_flags_cls->freeze();
......
......@@ -198,7 +198,6 @@ test_sqlite [unknown]
test_ssl [unknown]
test_startfile [unknown]
test_str memory leak?
test_strtod [unknown]
test_structmembers [unknown]
test_struct [unknown]
test_subprocess exit code 141 [sigpipe?], no error message
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment