Skip to content

Commit 7489776

Browse files
authored
[decimal] Implement a subtraction function for BigDecimal (#67)
This pull request includes several changes to the `benches/bigdecimal/bench.mojo`, `mojoproject.toml`, and `src/decimojo/bigdecimal/arithmetics.mojo` files to add new functionality and improve the codebase. The most important changes include adding a new subtraction benchmark, renaming benchmark commands, and implementing a subtraction function for `BigDecimal`. ### New functionality: * Added a new subtraction benchmark by importing `bench_bigdecimal_subtract` and updating the benchmark commands in `benches/bigdecimal/bench.mojo`. [[1]](diffhunk://#diff-96175f1000f81fe074f70a9adc4b39cd3f2dac8e85d30aa7efed9fc02b46e5ecR2) [[2]](diffhunk://#diff-96175f1000f81fe074f70a9adc4b39cd3f2dac8e85d30aa7efed9fc02b46e5ecR12) [[3]](diffhunk://#diff-96175f1000f81fe074f70a9adc4b39cd3f2dac8e85d30aa7efed9fc02b46e5ecR21-R25) * Implemented the `subtract` function for `BigDecimal` in `src/decimojo/bigdecimal/arithmetics.mojo`, including handling zero operands and ensuring operands have the same scale. ### Codebase improvements: * Renamed benchmark commands in `mojoproject.toml` for consistency and clarity. * Added notes to the `add` function in `src/decimojo/bigdecimal/arithmetics.mojo` to clarify its behavior and result properties. * Added the `__sub__` method to the `BigDecimal` struct in `src/decimojo/bigdecimal/bigdecimal.mojo` to support subtraction using the new `subtract` function.
1 parent 23f2e07 commit 7489776

File tree

6 files changed

+812
-4
lines changed

6 files changed

+812
-4
lines changed

benches/bigdecimal/bench.mojo

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from bench_bigdecimal_add import main as bench_add
2+
from bench_bigdecimal_subtract import main as bench_sub
23

34

45
fn main() raises:
@@ -8,6 +9,7 @@ fn main() raises:
89
This is the BigInt Benchmarks
910
=========================================
1011
add: Add
12+
sub: Subtract
1113
all: Run all benchmarks
1214
q: Exit
1315
=========================================
@@ -16,8 +18,11 @@ q: Exit
1618
var command = input("Type name of bench you want to run: ")
1719
if command == "add":
1820
bench_add()
21+
elif command == "sub":
22+
bench_sub()
1923
elif command == "all":
2024
bench_add()
25+
bench_sub()
2126
elif command == "q":
2227
return
2328
else:

0 commit comments

Comments
 (0)