Make docstrings for `as_integer_ratio` consistent across types, and document that
the returned pair is always normalized (coprime integers, with positive denominator).
---------
Co-authored-by: Owain Davies <116417456+OTheDev@users.noreply.github.com>
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
.. method:: as_integer_ratio()
Return a tuple of two integers, whose ratio is equal
- to the Fraction and with a positive denominator.
+ to the original Fraction. The ratio is in lowest terms
+ and has a positive denominator.
.. versionadded:: 3.8
.. method:: int.as_integer_ratio()
- Return a pair of integers whose ratio is exactly equal to the original
- integer and with a positive denominator. The integer ratio of integers
+ Return a pair of integers whose ratio is equal to the original
+ integer and has a positive denominator. The integer ratio of integers
(whole numbers) is always the integer as the numerator and ``1`` as the
denominator.
.. method:: float.as_integer_ratio()
Return a pair of integers whose ratio is exactly equal to the
- original float and with a positive denominator. Raises
+ original float. The ratio is in lowest terms and has a positive denominator. Raises
:exc:`OverflowError` on infinities and a :exc:`ValueError` on
NaNs.
return self._denominator == 1
def as_integer_ratio(self):
- """Return the integer ratio as a tuple.
+ """Return a pair of integers, whose ratio is equal to the original Fraction.
- Return a tuple of two integers, whose ratio is equal to the
- Fraction and with a positive denominator.
+ The ratio is in lowest terms and has a positive denominator.
"""
return (self._numerator, self._denominator)
"as_integer_ratio($self, /)\n"
"--\n"
"\n"
-"Return integer ratio.\n"
+"Return a pair of integers, whose ratio is exactly equal to the original float.\n"
"\n"
-"Return a pair of integers, whose ratio is exactly equal to the original float\n"
-"and with a positive denominator.\n"
-"\n"
-"Raise OverflowError on infinities and a ValueError on NaNs.\n"
+"The ratio is in lowest terms and has a positive denominator. Raise\n"
+"OverflowError on infinities and a ValueError on NaNs.\n"
"\n"
">>> (10.0).as_integer_ratio()\n"
"(10, 1)\n"
exit:
return return_value;
}
-/*[clinic end generated code: output=74bc91bb44014df9 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ea329577074911b9 input=a9049054013a1b77]*/
"as_integer_ratio($self, /)\n"
"--\n"
"\n"
-"Return integer ratio.\n"
+"Return a pair of integers, whose ratio is equal to the original int.\n"
"\n"
-"Return a pair of integers, whose ratio is exactly equal to the original int\n"
-"and with a positive denominator.\n"
+"The ratio is in lowest terms and has a positive denominator.\n"
"\n"
">>> (10).as_integer_ratio()\n"
"(10, 1)\n"
{
return int_is_integer_impl(self);
}
-/*[clinic end generated code: output=e518fe2b5d519322 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=cfdf35d916158d4f input=a9049054013a1b77]*/
/*[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)
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;
/*[clinic input]
int.as_integer_ratio
-Return integer ratio.
+Return a pair of integers, whose ratio is equal to the original int.
-Return a pair of integers, whose ratio is exactly equal to the original int
-and with a positive denominator.
+The ratio is in lowest terms and has a positive denominator.
>>> (10).as_integer_ratio()
(10, 1)
static PyObject *
int_as_integer_ratio_impl(PyObject *self)
-/*[clinic end generated code: output=e60803ae1cc8621a input=55ce3058e15de393]*/
+/*[clinic end generated code: output=e60803ae1cc8621a input=384ff1766634bec2]*/
{
PyObject *ratio_tuple;
PyObject *numerator = long_long(self);