Skip to content

Rounding behaviour of BigDecimal #236

Description

@forfudan

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

  1. Round the results to PRECISION for all arithemtic dunders and in-place dunders.
  2. Create corresponding arithmetic methods that accept the precision argument.
  3. When Mojo support module-level variables, replace the precision argument as a config variable.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions