Python runtime: Money division can simply use Integer division to remain rational

This is cleaner than referencing `mpq` explicitly, as it still returns a `Decimal` with full rational (non-floating) precision.
This commit is contained in:
Rohan Padhye 2023-02-20 22:40:05 -05:00 committed by GitHub
parent 6c1963e7dd
commit 940485dca4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -151,7 +151,7 @@ class Money:
def __truediv__(self, other: 'Money') -> Decimal:
if isinstance(other, Money):
return Decimal(mpq(self.value.value, other.value.value))
return self.value / other.value
elif isinstance(other, Decimal):
return self * (1. / other.value)
else: