Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions 3 Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ always available.

.. versionadded:: 3.1

.. versionchanged:: 3.11
The value is now always ``'short'``.


.. function:: getallocatedblocks()

Expand Down
6 changes: 6 additions & 0 deletions 6 Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ sys
(equivalent to ``sys.exc_info()[1]``).
(Contributed by Irit Katriel in :issue:`46328`.)

* :data:`sys.float_repr_style` is now always ``'short'``.
(Contributed by Victor Stinner in :issue:`46852`.)

threading
---------

Expand Down Expand Up @@ -646,6 +649,9 @@ Build Changes
remove the ``Py_NO_NAN`` macro.
(Contributed by Victor Stinner in :issue:`46656`.)

* Building Python now requires IEEE 754 (floating point) support.
(Contributed by Victor Stinner in :issue:`46852`.)

* Freelists for object structs can now be disabled. A new :program:`configure`
option :option:`!--without-freelists` can be used to disable all freelists
except empty tuple singleton.
Expand Down
7 changes: 0 additions & 7 deletions 7 Include/internal/pycore_dtoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR


#if _PY_SHORT_FLOAT_REPR == 1

/* These functions are used by modules compiled as C extension like math:
they must be exported. */

Expand All @@ -21,8 +16,6 @@ PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
PyAPI_FUNC(double) _Py_dg_stdnan(int sign);
PyAPI_FUNC(double) _Py_dg_infinity(int sign);

#endif // _PY_SHORT_FLOAT_REPR == 1

#ifdef __cplusplus
}
#endif
10 changes: 3 additions & 7 deletions 10 Include/internal/pycore_pymath.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ extern void _Py_set_387controlword(unsigned short);
#endif


//--- _PY_SHORT_FLOAT_REPR macro -------------------------------------------
//--- Make sure that IEEE 754 is supported ---------------------------------

// If we can't guarantee 53-bit precision, don't use the code
// in Python/dtoa.c, but fall back to standard code. This
Expand All @@ -203,18 +203,14 @@ extern void _Py_set_387controlword(unsigned short);
#if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \
!defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \
!defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)
# define _PY_SHORT_FLOAT_REPR 0
# error "Building Python requires IEEE 754 support"
#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_SHORT_FLOAT_REPR 0
#endif

#ifndef _PY_SHORT_FLOAT_REPR
# define _PY_SHORT_FLOAT_REPR 1
# error "Building Python requires IEEE 754 support"
#endif


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Building Python now requires IEEE 754 (floating point) support. Patch by
Victor Stinner.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:data:`sys.float_repr_style` is now always ``'short'``. Patch by Victor
Stinner.
21 changes: 0 additions & 21 deletions 21 Modules/cmathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#endif

#include "Python.h"
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
#include "pycore_dtoa.h" // _Py_dg_stdnan()
/* we need DBL_MAX, DBL_MIN, DBL_EPSILON, DBL_MANT_DIG and FLT_RADIX from
float.h. We assume that FLT_RADIX is either 2 or 16. */
Expand Down Expand Up @@ -88,20 +87,10 @@ else {
#endif
#define CM_SCALE_DOWN (-(CM_SCALE_UP+1)/2)

/* Constants cmath.inf, cmath.infj, cmath.nan, cmath.nanj.
cmath.nan and cmath.nanj are defined only when either
_PY_SHORT_FLOAT_REPR is 1 (which should be
the most common situation on machines using an IEEE 754
representation), or Py_NAN is defined. */

static double
m_inf(void)
{
#if _PY_SHORT_FLOAT_REPR == 1
return _Py_dg_infinity(0);
#else
return Py_HUGE_VAL;
#endif
}

static Py_complex
Expand All @@ -113,16 +102,10 @@ c_infj(void)
return r;
}

#if _PY_SHORT_FLOAT_REPR == 1

static double
m_nan(void)
{
#if _PY_SHORT_FLOAT_REPR == 1
return _Py_dg_stdnan(0);
#else
return Py_NAN;
#endif
}

static Py_complex
Expand All @@ -134,8 +117,6 @@ c_nanj(void)
return r;
}

#endif

/* forward declarations */
static Py_complex cmath_asinh_impl(PyObject *, Py_complex);
static Py_complex cmath_atanh_impl(PyObject *, Py_complex);
Expand Down Expand Up @@ -1282,15 +1263,13 @@ cmath_exec(PyObject *mod)
PyComplex_FromCComplex(c_infj())) < 0) {
return -1;
}
#if _PY_SHORT_FLOAT_REPR == 1
if (PyModule_AddObject(mod, "nan", PyFloat_FromDouble(m_nan())) < 0) {
return -1;
}
if (PyModule_AddObject(mod, "nanj",
PyComplex_FromCComplex(c_nanj())) < 0) {
return -1;
}
#endif

/* initialize special value tables */

Expand Down
15 changes: 0 additions & 15 deletions 15 Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ raised for division by zero and mod by zero.
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_dtoa.h" // _Py_dg_infinity()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
/* For DBL_EPSILON in _math.h */
#include <float.h>
/* For _Py_log1p with workarounds for buggy handling of zeros. */
Expand Down Expand Up @@ -273,30 +272,18 @@ lanczos_sum(double x)
static double
m_inf(void)
{
#if _PY_SHORT_FLOAT_REPR == 1
return _Py_dg_infinity(0);
#else
return Py_HUGE_VAL;
#endif
}

/* Constant nan value, generated in the same way as float('nan'). */
/* We don't currently assume that Py_NAN is defined everywhere. */

#if _PY_SHORT_FLOAT_REPR == 1

static double
m_nan(void)
{
#if _PY_SHORT_FLOAT_REPR == 1
return _Py_dg_stdnan(0);
#else
return Py_NAN;
#endif
}

#endif

static double
m_tgamma(double x)
{
Expand Down Expand Up @@ -3838,11 +3825,9 @@ math_exec(PyObject *module)
if (PyModule_AddObject(module, "inf", PyFloat_FromDouble(m_inf())) < 0) {
return -1;
}
#if _PY_SHORT_FLOAT_REPR == 1
if (PyModule_AddObject(module, "nan", PyFloat_FromDouble(m_nan())) < 0) {
return -1;
}
#endif
return 0;
}

Expand Down
71 changes: 3 additions & 68 deletions 71 Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "pycore_interp.h" // _PyInterpreterState.float_state
#include "pycore_long.h" // _PyLong_GetOne()
#include "pycore_object.h" // _PyObject_Init()
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
#include "pycore_pymath.h" // _Py_SET_53BIT_PRECISION_START
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_structseq.h" // _PyStructSequence_FiniType()

Expand Down Expand Up @@ -932,10 +932,8 @@ float___ceil___impl(PyObject *self)
ndigits <= 323). Returns a Python float, or sets a Python error and
returns NULL on failure (OverflowError and memory errors are possible). */

#if _PY_SHORT_FLOAT_REPR == 1
/* version of double_round that uses the correctly-rounded string<->double
conversions from Python/dtoa.c */

// Rounding that uses the correctly-rounded string<->double conversions
// from Python/dtoa.c
static PyObject *
double_round(double x, int ndigits) {

Expand Down Expand Up @@ -989,58 +987,6 @@ double_round(double x, int ndigits) {
return result;
}

#else // _PY_SHORT_FLOAT_REPR == 0

/* fallback version, to be used when correctly rounded binary<->decimal
conversions aren't available */

static PyObject *
double_round(double x, int ndigits) {
double pow1, pow2, y, z;
if (ndigits >= 0) {
if (ndigits > 22) {
/* pow1 and pow2 are each safe from overflow, but
pow1*pow2 ~= pow(10.0, ndigits) might overflow */
pow1 = pow(10.0, (double)(ndigits-22));
pow2 = 1e22;
}
else {
pow1 = pow(10.0, (double)ndigits);
pow2 = 1.0;
}
y = (x*pow1)*pow2;
/* if y overflows, then rounded value is exactly x */
if (!Py_IS_FINITE(y))
return PyFloat_FromDouble(x);
}
else {
pow1 = pow(10.0, (double)-ndigits);
pow2 = 1.0; /* unused; silences a gcc compiler warning */
y = x / pow1;
}

z = round(y);
if (fabs(y-z) == 0.5)
/* halfway between two integers; use round-half-even */
z = 2.0*round(y/2.0);

if (ndigits >= 0)
z = (z / pow2) / pow1;
else
z *= pow1;

/* if computation resulted in overflow, raise OverflowError */
if (!Py_IS_FINITE(z)) {
PyErr_SetString(PyExc_OverflowError,
"overflow occurred during round");
return NULL;
}

return PyFloat_FromDouble(z);
}

#endif // _PY_SHORT_FLOAT_REPR == 0

/* round a Python float v to the closest multiple of 10**-ndigits */

/*[clinic input]
Expand Down Expand Up @@ -2407,16 +2353,6 @@ _PyFloat_Unpack2(const unsigned char *p, int le)
f |= *p;

if (e == 0x1f) {
#if _PY_SHORT_FLOAT_REPR == 0
if (f == 0) {
/* Infinity */
return sign ? -Py_HUGE_VAL : Py_HUGE_VAL;
}
else {
/* NaN */
return sign ? -Py_NAN : Py_NAN;
}
#else // _PY_SHORT_FLOAT_REPR == 1
if (f == 0) {
/* Infinity */
return _Py_dg_infinity(sign);
Expand All @@ -2425,7 +2361,6 @@ _PyFloat_Unpack2(const unsigned char *p, int le)
/* NaN */
return _Py_dg_stdnan(sign);
}
#endif // _PY_SHORT_FLOAT_REPR == 1
}

x = (double)f / 1024.0;
Expand Down
9 changes: 2 additions & 7 deletions 9 Python/dtoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,9 @@
/* Linking of Python's #defines to Gay's #defines starts here. */

#include "Python.h"
#include "pycore_dtoa.h" // _PY_SHORT_FLOAT_REPR
#include "pycore_dtoa.h" // _Py_dg_stdnan()
#include <stdlib.h> // exit()

/* if _PY_SHORT_FLOAT_REPR == 0, then don't even try to compile
the following code */
#if _PY_SHORT_FLOAT_REPR == 1

#include "float.h"

#define MALLOC PyMem_Malloc
Expand Down Expand Up @@ -2853,8 +2849,7 @@ _Py_dg_dtoa(double dd, int mode, int ndigits,
_Py_dg_freedtoa(s0);
return NULL;
}

#ifdef __cplusplus
}
#endif

#endif // _PY_SHORT_FLOAT_REPR == 1
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.