From f724ae0b93c96ff09ab51b62e2b26646813bb35e Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Thu, 14 Jan 2021 02:17:16 +1100 Subject: [PATCH] Fix bug in --numbers fixed in Python where results would not be rounded after division --- pyRCV2/numbers/fixed_py.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pyRCV2/numbers/fixed_py.py b/pyRCV2/numbers/fixed_py.py index 29c9709..c3a0ea0 100644 --- a/pyRCV2/numbers/fixed_py.py +++ b/pyRCV2/numbers/fixed_py.py @@ -46,6 +46,17 @@ class Fixed(BasePyNum): """Overrides BasePyNum._to_impl""" return decimal.Decimal(value).quantize(_quantize_exp) + @classmethod + def _truediv_impl(cls, i1, i2): + """Implements BaseNum._truediv_impl""" + return (i1 / i2).quantize(_quantize_exp) + + @compatible_types + def __itruediv__(self, other): + """Overrides BaseNum.__itruediv__""" + self.impl = (self.impl / other.impl).quantize(_quantize_exp) + return self + def round(self, dps, mode): """Implements BaseNum.round""" return Fixed._from_impl(self.impl.quantize(decimal.Decimal('10') ** -dps, mode))