Added more documentation on how mixed-mode arithmetic should be implemented. I

also noticed and fixed a bug in Rational's forward operators (they were
claiming all instances of numbers.Rational instead of just the concrete types).
This commit is contained in:
Jeffrey Yasskin 2008-01-31 07:44:11 +00:00
parent e973c61238
commit b23dea6adb
3 changed files with 222 additions and 13 deletions

View file

@ -292,7 +292,13 @@ class Rational(Real, Exact):
# Concrete implementation of Real's conversion to float.
def __float__(self):
"""float(self) = self.numerator / self.denominator"""
"""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