Skip to content

Commit fae5676

Browse files
authored
[integer] Enhance the comparison operations of BigInt (#60)
This pull request includes significant changes to the `BigInt` and `BigUInt` benchmarks and arithmetic operations. The changes improve the initialization and handling of `BigInt` objects, update the benchmarks to use more descriptive commands, and enhance the comparison operations. Below are the most important changes: ### Benchmark Improvements: * [`benches/bigint/bench.mojo`](diffhunk://#diff-2a97f8dc8465f7a88d361dcee4dcb3020bd75f18a3a189e817fb9af8996bbb75R2): Added the import for `bench_bigint_multiply` and updated the command options to use descriptive strings instead of numbers. [[1]](diffhunk://#diff-2a97f8dc8465f7a88d361dcee4dcb3020bd75f18a3a189e817fb9af8996bbb75R2) [[2]](diffhunk://#diff-2a97f8dc8465f7a88d361dcee4dcb3020bd75f18a3a189e817fb9af8996bbb75L12-R36) * [`benches/biguint/bench.mojo`](diffhunk://#diff-34a58f6f5c1b673b01199db91a3b182f1f345caf0797cbcacadd978e96e4cc10L12-R31): Updated the command options to use descriptive strings instead of numbers. ### BigInt Initialization and Arithmetic Enhancements: * [`src/decimojo/bigint/arithmetics.mojo`](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL54-R57): Replaced the `empty` and `capacity` parameters with `List[UInt32]` for initializing `BigInt` objects in various arithmetic functions. [[1]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL54-R57) [[2]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL120-R121) [[3]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL227-R228) [[4]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL346-R358) [[5]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL393-R393) [[6]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL419-R419) [[7]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL431-R431) [[8]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL484-R484) [[9]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL505-R505) [[10]](diffhunk://#diff-1ffcd7baf2074053c5e9680efda5d243ac5a3096ebf39049f4670a48bc0a932fL523-R523) ### BigInt Struct Enhancements: * [`src/decimojo/bigint/bigint.mojo`](diffhunk://#diff-d65a756a58e3387a2b30bbe88308c3b318d71d2116b2870ac0a44109729e554bL76-R128): Deprecated the `empty` and `capacity` parameters in `BigInt` initialization, introduced new constructors for safer initialization from lists and words, and added comparison dunders (`__gt__`, `__ge__`, `__lt__`, `__le__`, `__eq__`, `__ne__`). [[1]](diffhunk://#diff-d65a756a58e3387a2b30bbe88308c3b318d71d2116b2870ac0a44109729e554bL76-R128) [[2]](diffhunk://#diff-d65a756a58e3387a2b30bbe88308c3b318d71d2116b2870ac0a44109729e554bR183-R202) [[3]](diffhunk://#diff-d65a756a58e3387a2b30bbe88308c3b318d71d2116b2870ac0a44109729e554bL179-R218) [[4]](diffhunk://#diff-d65a756a58e3387a2b30bbe88308c3b318d71d2116b2870ac0a44109729e554bL189-R239) [[5]](diffhunk://#diff-d65a756a58e3387a2b30bbe88308c3b318d71d2116b2870ac0a44109729e554bL208-R260) [[6]](diffhunk://#diff-d65a756a58e3387a2b30bbe88308c3b318d71d2116b2870ac0a44109729e554bL236-R277) [[7]](diffhunk://#diff-d65a756a58e3387a2b30bbe88308c3b318d71d2116b2870ac0a44109729e554bL262-R301) [[8]](diffhunk://#diff-d65a756a58e3387a2b30bbe88308c3b318d71d2116b2870ac0a44109729e554bR472-R506) [[9]](diffhunk://#diff-d65a756a58e3387a2b30bbe88308c3b318d71d2116b2870ac0a44109729e554bR518-R524) [[10]](diffhunk://#diff-d65a756a58e3387a2b30bbe88308c3b318d71d2116b2870ac0a44109729e554bL495-R575) ### Comparison Module Update: * [`src/decimojo/bigint/comparison.mojo`](diffhunk://#diff-d7e30fa4bdf75c4935df70d55fd5fe8b02a9530e5a3f012fe61958a0b82311ccL21-R22): Removed unnecessary import and added the import for `BigUInt`.
1 parent 3cc20ea commit fae5676

File tree

7 files changed

+1125
-106
lines changed

7 files changed

+1125
-106
lines changed

benches/bigint/bench.mojo

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from bench_bigint_add import main as bench_add
2+
from bench_bigint_multiply import main as bench_multiply
23
from bench_bigint_truncate_divide import main as bench_truncate_divide
34
from bench_bigint_floor_divide import main as bench_floor_divide
45

@@ -9,26 +10,30 @@ fn main() raises:
910
=========================================
1011
This is the BigInt Benchmarks
1112
=========================================
12-
1: Add
13-
2: Truncate Divide
14-
3: Floor Divide
15-
4: Run all benchmarks
16-
5: Exit
13+
add: Add
14+
mul: Multiply
15+
trunc: Truncate divide
16+
floor: Floor divide (//)
17+
all: Run all benchmarks
18+
q: Exit
1719
=========================================
1820
"""
1921
)
2022
var command = input("Type the number of the bench you want to run: ")
21-
if command == "1":
23+
if command == "add":
2224
bench_add()
23-
elif command == "2":
25+
elif command == "mul":
26+
bench_multiply()
27+
elif command == "trunc":
2428
bench_truncate_divide()
25-
elif command == "3":
29+
elif command == "floor":
2630
bench_floor_divide()
27-
elif command == "4":
31+
elif command == "all":
2832
bench_add()
33+
bench_multiply()
2934
bench_truncate_divide()
3035
bench_floor_divide()
31-
elif command == "5":
36+
elif command == "q":
3237
return
3338
else:
3439
print("Invalid input")

0 commit comments

Comments
 (0)