mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
bpo-45412: Add _PY_SHORT_FLOAT_REPR macro (GH-31171)
Remove the HAVE_PY_SET_53BIT_PRECISION macro (moved to the internal C API). * Move HAVE_PY_SET_53BIT_PRECISION macro to pycore_pymath.h. * Replace PY_NO_SHORT_FLOAT_REPR macro with _PY_SHORT_FLOAT_REPR macro which is always defined. gcc -Wundef emits a warning when using _PY_SHORT_FLOAT_REPR but the macro is not defined, if pycore_pymath.h include was forgotten.
This commit is contained in:
parent
375a56bd40
commit
9bbdde2180
11 changed files with 104 additions and 96 deletions
|
@ -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_ADJUST_ERANGE1()
|
||||
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
|
||||
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
||||
#include "pycore_structseq.h" // _PyStructSequence_FiniType()
|
||||
|
||||
|
@ -932,7 +932,7 @@ 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). */
|
||||
|
||||
#ifndef PY_NO_SHORT_FLOAT_REPR
|
||||
#if _PY_SHORT_FLOAT_REPR == 1
|
||||
/* version of double_round that uses the correctly-rounded string<->double
|
||||
conversions from Python/dtoa.c */
|
||||
|
||||
|
@ -989,7 +989,7 @@ double_round(double x, int ndigits) {
|
|||
return result;
|
||||
}
|
||||
|
||||
#else /* PY_NO_SHORT_FLOAT_REPR */
|
||||
#else // _PY_SHORT_FLOAT_REPR == 0
|
||||
|
||||
/* fallback version, to be used when correctly rounded binary<->decimal
|
||||
conversions aren't available */
|
||||
|
@ -1039,7 +1039,7 @@ double_round(double x, int ndigits) {
|
|||
return PyFloat_FromDouble(z);
|
||||
}
|
||||
|
||||
#endif /* PY_NO_SHORT_FLOAT_REPR */
|
||||
#endif // _PY_SHORT_FLOAT_REPR == 0
|
||||
|
||||
/* round a Python float v to the closest multiple of 10**-ndigits */
|
||||
|
||||
|
@ -2479,7 +2479,7 @@ _PyFloat_Unpack2(const unsigned char *p, int le)
|
|||
f |= *p;
|
||||
|
||||
if (e == 0x1f) {
|
||||
#ifdef PY_NO_SHORT_FLOAT_REPR
|
||||
#if _PY_SHORT_FLOAT_REPR == 0
|
||||
if (f == 0) {
|
||||
/* Infinity */
|
||||
return sign ? -Py_HUGE_VAL : Py_HUGE_VAL;
|
||||
|
@ -2494,9 +2494,9 @@ _PyFloat_Unpack2(const unsigned char *p, int le)
|
|||
"can't unpack IEEE 754 NaN "
|
||||
"on platform that does not support NaNs");
|
||||
return -1;
|
||||
#endif /* #ifdef Py_NAN */
|
||||
#endif // !defined(Py_NAN)
|
||||
}
|
||||
#else
|
||||
#else // _PY_SHORT_FLOAT_REPR == 1
|
||||
if (f == 0) {
|
||||
/* Infinity */
|
||||
return _Py_dg_infinity(sign);
|
||||
|
@ -2505,7 +2505,7 @@ _PyFloat_Unpack2(const unsigned char *p, int le)
|
|||
/* NaN */
|
||||
return _Py_dg_stdnan(sign);
|
||||
}
|
||||
#endif /* #ifdef PY_NO_SHORT_FLOAT_REPR */
|
||||
#endif // _PY_SHORT_FLOAT_REPR == 1
|
||||
}
|
||||
|
||||
x = (double)f / 1024.0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue