summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-02-01 22:15:52 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-02-01 22:15:52 (GMT)
commitc9e928ae0fbb56aed59d370c558697d996b670bf (patch)
tree0982500efeda8335a1383c073e26e79636eaa178 /Objects
parent04c96d52a4be897792e3ad5c6ad77775aaa18d4b (diff)
downloadcpython-c9e928ae0fbb56aed59d370c558697d996b670bf.zip
cpython-c9e928ae0fbb56aed59d370c558697d996b670bf.tar.gz
cpython-c9e928ae0fbb56aed59d370c558697d996b670bf.tar.bz2
Integer ratio should return ints instead of longs whereever possible.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index a3733fc..ce6926b 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1201,8 +1201,8 @@ float_as_integer_ratio(PyObject *v, PyObject *unused)
if (numerator == NULL) goto error;
/* now self = numerator * 2**exponent exactly; fold in 2**exponent */
- denominator = PyInt_FromLong(1);
- py_exponent = PyInt_FromLong(labs(exponent));
+ denominator = PyLong_FromLong(1);
+ py_exponent = PyLong_FromLong(labs(exponent));
if (py_exponent == NULL) goto error;
INPLACE_UPDATE(py_exponent,
long_methods->nb_lshift(denominator, py_exponent));
@@ -1219,6 +1219,12 @@ float_as_integer_ratio(PyObject *v, PyObject *unused)
py_exponent = NULL;
}
+ /* Returns ints instead of longs where possible */
+ INPLACE_UPDATE(numerator, PyNumber_Int(numerator));
+ if (numerator == NULL) goto error;
+ INPLACE_UPDATE(denominator, PyNumber_Int(denominator));
+ if (denominator == NULL) goto error;
+
result_pair = PyTuple_Pack(2, numerator, denominator);
#undef INPLACE_UPDATE