[issue23975] numbers.Rational implements __float__ incorrectly

2021-04-25 Thread Sergey B Kirpichev
Change by Sergey B Kirpichev : -- pull_requests: +24321 stage: -> patch review pull_request: https://github.com/python/cpython/pull/25619 ___ Python tracker ___

[issue23975] numbers.Rational implements __float__ incorrectly

2021-04-23 Thread Sergey B Kirpichev
Change by Sergey B Kirpichev : -- nosy: +Sergey.Kirpichev ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue23975] numbers.Rational implements __float__ incorrectly

2015-04-27 Thread Wolfgang Maier
Wolfgang Maier added the comment: After considering this for a while, I think: return float(self.numerator / self.denominator) is the best solution: * it is simple and works reasonably well as a default * it fixes Rational.__float__ for cases, in which numerator / denominator returns a

[issue23975] numbers.Rational implements __float__ incorrectly

2015-04-20 Thread Paul Moore
Paul Moore added the comment: Alternatively, return int(self.numerator) / int(self.denominator). After all, a fraction whose numerator can't be represented as a Python (unlimited precision) integer is a pretty odd sort of fraction... -- ___ Python

[issue23975] numbers.Rational implements __float__ incorrectly

2015-04-20 Thread Paul Moore
Paul Moore added the comment: Is it not reasonable to simply say that implementations of numbers.Rational which allow the numerator and denominator to have types for which true division doesn't return a float, have to provide their own implementation of __float__()? It's certainly less

[issue23975] numbers.Rational implements __float__ incorrectly

2015-04-20 Thread Wolfgang Maier
Wolfgang Maier added the comment: Is it not reasonable to simply say that implementations of numbers.Rational which allow the numerator and denominator to have types for which true division doesn't return a float, have to provide their own implementation of __float__()? Unfortunately,

[issue23975] numbers.Rational implements __float__ incorrectly

2015-04-20 Thread Wolfgang Maier
Wolfgang Maier added the comment: Good point. If the numbers ABC guaranteed numerator and denominator to be Integral numbers, this could be solved by: return float(int(self.numerator) / int(self.denominator)) but since both could be Rationals again that does not seem to be an option either.

[issue23975] numbers.Rational implements __float__ incorrectly

2015-04-17 Thread Mark Dickinson
Mark Dickinson added the comment: What happens if `self.numerator / self.denominator` returns another `Rational` instance? If I create `MyRational` and `MyInteger` classes, such that the quotient of two `MyInteger` instances is a `MyRational` instance and the numerator and denominator of a

[issue23975] numbers.Rational implements __float__ incorrectly

2015-04-16 Thread Wolfgang Maier
New submission from Wolfgang Maier: numbers.Rational defines __float__ like this: def __float__(self): float(self) = self.numerator / self.denominator It's important that this conversion use the integer's true division rather than casting one side to float before dividing so

[issue23975] numbers.Rational implements __float__ incorrectly

2015-04-16 Thread R. David Murray
Changes by R. David Murray rdmur...@bitdance.com: -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23975 ___ ___