Kaydet (Commit) c9e928ae authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Integer ratio should return ints instead of longs whereever possible.

üst 04c96d52
...@@ -1201,8 +1201,8 @@ float_as_integer_ratio(PyObject *v, PyObject *unused) ...@@ -1201,8 +1201,8 @@ float_as_integer_ratio(PyObject *v, PyObject *unused)
if (numerator == NULL) goto error; if (numerator == NULL) goto error;
/* now self = numerator * 2**exponent exactly; fold in 2**exponent */ /* now self = numerator * 2**exponent exactly; fold in 2**exponent */
denominator = PyInt_FromLong(1); denominator = PyLong_FromLong(1);
py_exponent = PyInt_FromLong(labs(exponent)); py_exponent = PyLong_FromLong(labs(exponent));
if (py_exponent == NULL) goto error; if (py_exponent == NULL) goto error;
INPLACE_UPDATE(py_exponent, INPLACE_UPDATE(py_exponent,
long_methods->nb_lshift(denominator, py_exponent)); long_methods->nb_lshift(denominator, py_exponent));
...@@ -1219,6 +1219,12 @@ float_as_integer_ratio(PyObject *v, PyObject *unused) ...@@ -1219,6 +1219,12 @@ float_as_integer_ratio(PyObject *v, PyObject *unused)
py_exponent = NULL; 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); result_pair = PyTuple_Pack(2, numerator, denominator);
#undef INPLACE_UPDATE #undef INPLACE_UPDATE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment