aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Objects/floatobject.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committershadchin <shadchin@yandex-team.com>2024-02-12 08:07:36 +0300
commitce1b7ca3171f9158180640c6a02a74b4afffedea (patch)
treee47c1e8391b1b0128262c1e9b1e6ed4c8fff2348 /contrib/tools/python3/src/Objects/floatobject.c
parent57350d96f030db90f220ce50ee591d5c5d403df7 (diff)
downloadydb-ce1b7ca3171f9158180640c6a02a74b4afffedea.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Objects/floatobject.c')
-rw-r--r--contrib/tools/python3/src/Objects/floatobject.c96
1 files changed, 38 insertions, 58 deletions
diff --git a/contrib/tools/python3/src/Objects/floatobject.c b/contrib/tools/python3/src/Objects/floatobject.c
index be6024659a..83a263c0d9 100644
--- a/contrib/tools/python3/src/Objects/floatobject.c
+++ b/contrib/tools/python3/src/Objects/floatobject.c
@@ -12,7 +12,7 @@
#include "pycore_object.h" // _PyObject_Init()
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
#include "pycore_pystate.h" // _PyInterpreterState_GET()
-#include "pycore_structseq.h" // _PyStructSequence_FiniType()
+#include "pycore_structseq.h" // _PyStructSequence_FiniBuiltin()
#include <ctype.h>
#include <float.h>
@@ -371,8 +371,7 @@ convert_to_double(PyObject **v, double *dbl)
}
}
else {
- Py_INCREF(Py_NotImplemented);
- *v = Py_NotImplemented;
+ *v = Py_NewRef(Py_NotImplemented);
return -1;
}
return 0;
@@ -532,20 +531,17 @@ float_richcompare(PyObject *v, PyObject *w, int op)
temp = _PyLong_Lshift(ww, 1);
if (temp == NULL)
goto Error;
- Py_DECREF(ww);
- ww = temp;
+ Py_SETREF(ww, temp);
temp = _PyLong_Lshift(vv, 1);
if (temp == NULL)
goto Error;
- Py_DECREF(vv);
- vv = temp;
+ Py_SETREF(vv, temp);
temp = PyNumber_Or(vv, _PyLong_GetOne());
if (temp == NULL)
goto Error;
- Py_DECREF(vv);
- vv = temp;
+ Py_SETREF(vv, temp);
}
r = PyObject_RichCompareBool(vv, ww, op);
@@ -904,8 +900,7 @@ float_is_integer_impl(PyObject *self)
PyExc_ValueError);
return NULL;
}
- Py_INCREF(o);
- return o;
+ return Py_NewRef(o);
}
/*[clinic input]
@@ -1124,11 +1119,12 @@ float___round___impl(PyObject *self, PyObject *o_ndigits)
static PyObject *
float_float(PyObject *v)
{
- if (PyFloat_CheckExact(v))
- Py_INCREF(v);
- else
- v = PyFloat_FromDouble(((PyFloatObject *)v)->ob_fval);
- return v;
+ if (PyFloat_CheckExact(v)) {
+ return Py_NewRef(v);
+ }
+ else {
+ return PyFloat_FromDouble(((PyFloatObject *)v)->ob_fval);
+ }
}
/*[clinic input]
@@ -1550,12 +1546,10 @@ float_fromhex(PyTypeObject *type, PyObject *string)
/*[clinic input]
float.as_integer_ratio
-Return integer ratio.
+Return a pair of integers, whose ratio is exactly equal to the original float.
-Return a pair of integers, whose ratio is exactly equal to the original float
-and with a positive denominator.
-
-Raise OverflowError on infinities and a ValueError on NaNs.
+The ratio is in lowest terms and has a positive denominator. Raise
+OverflowError on infinities and a ValueError on NaNs.
>>> (10.0).as_integer_ratio()
(10, 1)
@@ -1567,7 +1561,7 @@ Raise OverflowError on infinities and a ValueError on NaNs.
static PyObject *
float_as_integer_ratio_impl(PyObject *self)
-/*[clinic end generated code: output=65f25f0d8d30a712 input=e21d08b4630c2e44]*/
+/*[clinic end generated code: output=65f25f0d8d30a712 input=d5ba7765655d75bd]*/
{
double self_double;
double float_part;
@@ -1724,12 +1718,14 @@ float___getnewargs___impl(PyObject *self)
}
/* this is for the benefit of the pack/unpack routines below */
+typedef enum _py_float_format_type float_format_type;
+#define unknown_format _py_float_format_unknown
+#define ieee_big_endian_format _py_float_format_ieee_big_endian
+#define ieee_little_endian_format _py_float_format_ieee_little_endian
-typedef enum {
- unknown_format, ieee_big_endian_format, ieee_little_endian_format
-} float_format_type;
+#define float_format (_PyRuntime.float_state.float_format)
+#define double_format (_PyRuntime.float_state.double_format)
-static float_format_type double_format, float_format;
/*[clinic input]
@classmethod
@@ -1930,13 +1926,9 @@ PyTypeObject PyFloat_Type = {
.tp_vectorcall = (vectorcallfunc)float_vectorcall,
};
-void
-_PyFloat_InitState(PyInterpreterState *interp)
+static void
+_init_global_state(void)
{
- if (!_Py_IsMainInterpreter(interp)) {
- return;
- }
-
float_format_type detected_double_format, detected_float_format;
/* We attempt to determine if this machine is using IEEE
@@ -1986,22 +1978,23 @@ _PyFloat_InitState(PyInterpreterState *interp)
float_format = detected_float_format;
}
-PyStatus
-_PyFloat_InitTypes(PyInterpreterState *interp)
+void
+_PyFloat_InitState(PyInterpreterState *interp)
{
if (!_Py_IsMainInterpreter(interp)) {
- return _PyStatus_OK();
- }
-
- if (PyType_Ready(&PyFloat_Type) < 0) {
- return _PyStatus_ERR("Can't initialize float type");
+ return;
}
+ _init_global_state();
+}
+PyStatus
+_PyFloat_InitTypes(PyInterpreterState *interp)
+{
/* Init float info */
- if (FloatInfoType.tp_name == NULL) {
- if (PyStructSequence_InitType2(&FloatInfoType, &floatinfo_desc) < 0) {
- return _PyStatus_ERR("can't init float info type");
- }
+ if (_PyStructSequence_InitBuiltin(interp, &FloatInfoType,
+ &floatinfo_desc) < 0)
+ {
+ return _PyStatus_ERR("can't init float info type");
}
return _PyStatus_OK();
@@ -2036,9 +2029,7 @@ _PyFloat_Fini(PyInterpreterState *interp)
void
_PyFloat_FiniType(PyInterpreterState *interp)
{
- if (_Py_IsMainInterpreter(interp)) {
- _PyStructSequence_FiniType(&FloatInfoType);
- }
+ _PyStructSequence_FiniBuiltin(interp, &FloatInfoType);
}
/* Print summary info about the state of the optimized allocator */
@@ -2433,25 +2424,14 @@ PyFloat_Unpack2(const char *data, 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);
- }
- else {
- /* NaN */
- return _Py_dg_stdnan(sign);
+ return sign ? -fabs(Py_NAN) : fabs(Py_NAN);
}
-#endif // _PY_SHORT_FLOAT_REPR == 1
}
x = (double)f / 1024.0;