Skip to content

Commit

Permalink
pythongh-101825: mention, that as_integer_ratio() output is normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Feb 12, 2023
1 parent dfc2e06 commit d3de603
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ class`. In addition, it provides a few more methods:

.. method:: int.as_integer_ratio()

Return a pair of integers whose ratio is exactly equal to the original
Return a pair of integers whose ratio is equal to the original
integer and with a positive denominator. The integer ratio of integers
(whole numbers) is always the integer as the numerator and ``1`` as the
denominator.
Expand All @@ -624,7 +624,7 @@ class`. float also has the following additional methods.
.. 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, is in lowest terms and with a positive denominator. Raises
:exc:`OverflowError` on infinities and a :exc:`ValueError` on
NaNs.

Expand Down
5 changes: 2 additions & 3 deletions Lib/fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,9 @@ def is_integer(self):
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 with a positive denominator.
"""
return (self._numerator, self._denominator)

Expand Down
10 changes: 4 additions & 6 deletions Objects/clinic/floatobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Objects/clinic/longobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1546,12 +1546,10 @@ float_fromhex(PyTypeObject *type, PyObject *string)
/*[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 with a positive denominator. Raise
OverflowError on infinities and a ValueError on NaNs.
>>> (10.0).as_integer_ratio()
(10, 1)
Expand All @@ -1563,7 +1561,7 @@ Raise OverflowError on infinities and a ValueError on NaNs.

static PyObject *
float_as_integer_ratio_impl(PyObject *self)
/*[clinic end generated code: output=65f25f0d8d30a712 input=e21d08b4630c2e44]*/
/*[clinic end generated code: output=65f25f0d8d30a712 input=75db3b49d292f077]*/
{
double self_double;
double float_part;
Expand Down
7 changes: 3 additions & 4 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6020,10 +6020,9 @@ int_bit_count_impl(PyObject *self)
/*[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 with a positive denominator.
>>> (10).as_integer_ratio()
(10, 1)
Expand All @@ -6035,7 +6034,7 @@ and with a positive denominator.

static PyObject *
int_as_integer_ratio_impl(PyObject *self)
/*[clinic end generated code: output=e60803ae1cc8621a input=55ce3058e15de393]*/
/*[clinic end generated code: output=e60803ae1cc8621a input=c60aa1da86b7a47b]*/
{
PyObject *ratio_tuple;
PyObject *numerator = long_long(self);
Expand Down

0 comments on commit d3de603

Please sign in to comment.