Skip to content

Commit 96b5a01

Browse files
authored
[decimal] Implement floor_divide and modulo functions (// and %) (#45)
This pull request introduces several new features and improvements to the `decimojo` library, focusing on arithmetic operations, benchmarking, and rounding modes. The most important changes include adding new arithmetic functions, updating benchmarks, and refining the rounding mode implementation. ### New Arithmetic Functions: * Added `floor_divide` and `modulo` functions to the `arithmetics.mojo` file. These functions provide integral division and remainder operations for `Decimal` types. ### Benchmark Updates: * Updated `benches/bench.mojo` to include new benchmarks for `floor_divide` and `modulo` operations. * Updated `mojoproject.toml` to include test and benchmark commands for `floor_divide` and `modulo`. ### Rounding Mode Improvements: * Refined the `RoundingMode` struct by renaming methods and aliases to use lowercase names, improving code readability and consistency. ### Code Simplification: * Simplified the `Decimal` struct by removing unnecessary exception handling in arithmetic dunder methods. * Removed redundant scientific exponent calculation method from the `Decimal` struct. ### Miscellaneous: * Updated the `__init__.mojo` file to import the new `divide`, `floor_divide`, and `modulo` functions. * Fixed the rounding mode in the `Decimal` struct to use the correct constant names.
1 parent 2f1bdb3 commit 96b5a01

11 files changed

Lines changed: 1564 additions & 67 deletions

benches/bench.mojo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ from bench_add import main as bench_add
22
from bench_subtract import main as bench_subtract
33
from bench_multiply import main as bench_multiply
44
from bench_divide import main as bench_divide
5+
from bench_floor_divide import main as bench_floor_divide
6+
from bench_modulo import main as bench_modulo
57
from bench_sqrt import main as bench_sqrt
68
from bench_from_float import main as bench_from_float
79
from bench_from_string import main as bench_from_string
@@ -21,6 +23,8 @@ fn main() raises:
2123
bench_subtract()
2224
bench_multiply()
2325
bench_divide()
26+
bench_floor_divide()
27+
bench_modulo()
2428
bench_sqrt()
2529
bench_from_float()
2630
bench_from_string()

0 commit comments

Comments
 (0)