Skip to content

Commit

Permalink
gh-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 9c54422
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 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
8 changes: 3 additions & 5 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 Down
5 changes: 2 additions & 3 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 Down

0 comments on commit 9c54422

Please sign in to comment.