Skip to content

Commit 3cc20ea

Browse files
authored
[integer] Update functions and methods for BigUInt (#59)
This pull request includes significant updates to the BigInt and BigUInt benchmark functionalities and arithmetic operations. The changes add new benchmark options and refactor the internal representation of BigInt operations to use the `magnitude` attribute instead of `words`. ### Benchmark Updates: * [`benches/bigint/bench.mojo`](diffhunk://#diff-2a97f8dc8465f7a88d361dcee4dcb3020bd75f18a3a189e817fb9af8996bbb75R3-R35): Added a new benchmark for floor division and updated the main function to include options for running different benchmarks. * [`benches/biguint/bench.mojo`](diffhunk://#diff-34a58f6f5c1b673b01199db91a3b182f1f345caf0797cbcacadd978e96e4cc10R7-R35): Updated the main function to include a menu for running different benchmarks. ### Refactoring BigInt Operations: * [`src/decimojo/bigint/arithmetics.mojo`](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL54-R56): Refactored the `add`, `subtract`, `multiply`, and `truncate_divide` functions to use `magnitude.words` instead of `words` for internal operations. This change affects how the arithmetic operations handle the internal representation of BigInt. [[1]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL54-R56) [[2]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL63-R84) [[3]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL117-R167) [[4]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL204-R213) [[5]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL218-R309) [[6]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL296-R341) [[7]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL307-R377) [[8]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL344-R442) [[9]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL404-R454) [[10]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL416-R488) [[11]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL472-R530) ### New Functionality: * [`src/decimojo/bigint/arithmetics.mojo`](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL452-R509): Added a new function `floor_divide` to perform floor division on BigInt numbers, rounding towards negative infinity.
1 parent a4ef3b1 commit 3cc20ea

File tree

11 files changed

+2901
-789
lines changed

11 files changed

+2901
-789
lines changed

benches/bigint/bench.mojo

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
11
from bench_bigint_add import main as bench_add
22
from bench_bigint_truncate_divide import main as bench_truncate_divide
3+
from bench_bigint_floor_divide import main as bench_floor_divide
34

45

56
fn main() raises:
6-
bench_add()
7-
bench_truncate_divide()
7+
print(
8+
"""
9+
=========================================
10+
This is the BigInt Benchmarks
11+
=========================================
12+
1: Add
13+
2: Truncate Divide
14+
3: Floor Divide
15+
4: Run all benchmarks
16+
5: Exit
17+
=========================================
18+
"""
19+
)
20+
var command = input("Type the number of the bench you want to run: ")
21+
if command == "1":
22+
bench_add()
23+
elif command == "2":
24+
bench_truncate_divide()
25+
elif command == "3":
26+
bench_floor_divide()
27+
elif command == "4":
28+
bench_add()
29+
bench_truncate_divide()
30+
bench_floor_divide()
31+
elif command == "5":
32+
return
33+
else:
34+
print("Invalid input")
35+
main()

0 commit comments

Comments
 (0)