This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Leengit
Recipients Leengit
Date 2022-02-17.17:27:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645118854.48.0.835738770183.issue46780@roundup.psfhosted.org>
In-reply-to
Content
For example, a string such as "0.167" could be rounded from anything in [0.1665, 0.1675).  Within that interval, the fraction with the lowest numerator and denominator is 1/6.

Here it is proposed that we add a new flag to the Fractions constructor, perhaps called `_assume_rounded`, which defaults to False and then yields no change from current behavior.  However, when it is True, the constructed Fraction first computes the range of the values that the input string could have been rounded from, and then computes the fraction in that half-open interval with the lowest numerator and denominator.  This is described at https://en.wikipedia.org/wiki/Continued_fraction#Best_rational_within_an_interval, which uses continued fractions to arrive at the answer.

For extra bells and whistles, we'd support strings like "0x0.2AAB" which is hexadecimal for 1/6 rounded to that many places.  In this case, we'd find 1/6 as the fraction with lowest numerator and denominator in the interval [0x0.2AAA8, 0x0.2AAB8).  Likewise for binary, octal, and any other formats supported by Python.
History
Date User Action Args
2022-02-17 17:27:34Leengitsetrecipients: + Leengit
2022-02-17 17:27:34Leengitsetmessageid: <1645118854.48.0.835738770183.issue46780@roundup.psfhosted.org>
2022-02-17 17:27:34Leengitlinkissue46780 messages
2022-02-17 17:27:34Leengitcreate