summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-12-29 20:55:48 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-12-29 20:55:48 (GMT)
commit4e6aad1f7ac4e91a5e6c44e8ab3a2105acd65d74 (patch)
tree8a84afe4a8c462f6913ad8c09428907c212e815e /Objects
parent0d250bc119489fa7d094d4a3fd2fd2fa0a508145 (diff)
downloadcpython-4e6aad1f7ac4e91a5e6c44e8ab3a2105acd65d74.zip
cpython-4e6aad1f7ac4e91a5e6c44e8ab3a2105acd65d74.tar.gz
cpython-4e6aad1f7ac4e91a5e6c44e8ab3a2105acd65d74.tar.bz2
Clean up float.as_integer_ratio().
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 2949174..eb60659 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1451,18 +1451,12 @@ float_as_integer_ratio(PyObject *v, PyObject *unused)
int exponent;
int i;
- PyObject *prev;
PyObject *py_exponent = NULL;
PyObject *numerator = NULL;
PyObject *denominator = NULL;
PyObject *result_pair = NULL;
PyNumberMethods *long_methods = PyLong_Type.tp_as_number;
-#define INPLACE_UPDATE(obj, call) \
- prev = obj; \
- obj = call; \
- Py_DECREF(prev); \
-
CONVERT_TO_DOUBLE(v, self);
if (Py_IS_INFINITY(self)) {
@@ -1489,29 +1483,31 @@ float_as_integer_ratio(PyObject *v, PyObject *unused)
to be truncated by PyLong_FromDouble(). */
numerator = PyLong_FromDouble(float_part);
- if (numerator == NULL) goto error;
+ if (numerator == NULL)
+ goto error;
+ denominator = PyLong_FromLong(1);
+ if (denominator == NULL)
+ goto error;
+ py_exponent = PyLong_FromLong(Py_ABS(exponent));
+ if (py_exponent == NULL)
+ goto error;
/* fold in 2**exponent */
- denominator = PyLong_FromLong(1);
- py_exponent = PyLong_FromLong(labs((long)exponent));
- if (py_exponent == NULL) goto error;
- INPLACE_UPDATE(py_exponent,
- long_methods->nb_lshift(denominator, py_exponent));
- if (py_exponent == NULL) goto error;
if (exponent > 0) {
- INPLACE_UPDATE(numerator,
- long_methods->nb_multiply(numerator, py_exponent));
- if (numerator == NULL) goto error;
+ Py_SETREF(numerator,
+ long_methods->nb_lshift(numerator, py_exponent));
+ if (numerator == NULL)
+ goto error;
}
else {
- Py_DECREF(denominator);
- denominator = py_exponent;
- py_exponent = NULL;
+ Py_SETREF(denominator,
+ long_methods->nb_lshift(denominator, py_exponent));
+ if (denominator == NULL)
+ goto error;
}
result_pair = PyTuple_Pack(2, numerator, denominator);
-#undef INPLACE_UPDATE
error:
Py_XDECREF(py_exponent);
Py_XDECREF(denominator);