mirror of
https://github.com/python/cpython.git
synced 2025-12-05 00:52:25 +00:00
Issue #27005: Optimized the float.fromhex() class method for exact float.
This commit is contained in:
parent
871639a6d5
commit
25885d1dc5
2 changed files with 8 additions and 6 deletions
|
|
@ -10,6 +10,9 @@ Release date: tba
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #27005: Optimized the float.fromhex() class method for exact float.
|
||||||
|
It is now 2 times faster.
|
||||||
|
|
||||||
- Issue #18531: Single var-keyword argument of dict subtype was passed
|
- Issue #18531: Single var-keyword argument of dict subtype was passed
|
||||||
unscathed to the C-defined function. Now it is converted to exact dict.
|
unscathed to the C-defined function. Now it is converted to exact dict.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1195,7 +1195,7 @@ Return a hexadecimal representation of a floating-point number.\n\
|
||||||
static PyObject *
|
static PyObject *
|
||||||
float_fromhex(PyObject *cls, PyObject *arg)
|
float_fromhex(PyObject *cls, PyObject *arg)
|
||||||
{
|
{
|
||||||
PyObject *result_as_float, *result;
|
PyObject *result;
|
||||||
double x;
|
double x;
|
||||||
long exp, top_exp, lsb, key_digit;
|
long exp, top_exp, lsb, key_digit;
|
||||||
char *s, *coeff_start, *s_store, *coeff_end, *exp_start, *s_end;
|
char *s, *coeff_start, *s_store, *coeff_end, *exp_start, *s_end;
|
||||||
|
|
@ -1410,11 +1410,10 @@ float_fromhex(PyObject *cls, PyObject *arg)
|
||||||
s++;
|
s++;
|
||||||
if (s != s_end)
|
if (s != s_end)
|
||||||
goto parse_error;
|
goto parse_error;
|
||||||
result_as_float = Py_BuildValue("(d)", negate ? -x : x);
|
result = PyFloat_FromDouble(negate ? -x : x);
|
||||||
if (result_as_float == NULL)
|
if (cls != (PyObject *)&PyFloat_Type && result != NULL) {
|
||||||
return NULL;
|
Py_SETREF(result, PyObject_CallFunctionObjArgs(cls, result));
|
||||||
result = PyObject_CallObject(cls, result_as_float);
|
}
|
||||||
Py_DECREF(result_as_float);
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
overflow_error:
|
overflow_error:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue