Background
Currently, BigDecimal's __add__, __sub__, __mul__ dunders return exact results without rounding to the PRECISION. This behaviour is different from that of Python.decimal library.
Expected behaviour
When users calling +/-/* or the corresponding dunders, the results should be rounded to the PRECISION.
Limitations
Because Mojo does not yet support module-level variables, PRECISION is pre-set to be 28 and cannot be modified by users. To enable users to get exact results or arbitrary precision, we can add some methods which accept a precision argument.
Roadmap
- Round the results to PRECISION for all arithemtic dunders and in-place dunders.
- Create corresponding arithmetic methods that accept the
precision argument.
- When Mojo support module-level variables, replace the precision argument as a config variable.
Background
Currently,
BigDecimal's__add__,__sub__,__mul__dunders return exact results without rounding to thePRECISION. This behaviour is different from that of Python.decimal library.Expected behaviour
When users calling
+/-/*or the corresponding dunders, the results should be rounded to the PRECISION.Limitations
Because Mojo does not yet support module-level variables,
PRECISIONis pre-set to be 28 and cannot be modified by users. To enable users to get exact results or arbitrary precision, we can add some methods which accept aprecisionargument.Roadmap
precisionargument.