Message241270
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 that ratios of huge integers convert without overflowing.
"""
return self.numerator / self.denominator
This assumes that division of two Integral numbers returns a float, which the numbers ABC does not enforce in any way.
IMO, the only logical assumption is that division of any two Integral or Rational numbers gives a Real, for which the ABC guarantees a __float__ method in turn.
So I think Rational.__float__ should
return float(self.numerator / self.denominator) |
|
Date |
User |
Action |
Args |
2015-04-16 20:06:57 | wolma | set | recipients:
+ wolma |
2015-04-16 20:06:57 | wolma | set | messageid: <1429214817.83.0.816258978912.issue23975@psf.upfronthosting.co.za> |
2015-04-16 20:06:57 | wolma | link | issue23975 messages |
2015-04-16 20:06:57 | wolma | create | |
|