Commit 8389aa3
authored
This pull request includes significant changes to the BigInt and
BigDecimal arithmetic operations, introducing new functionality and
improving existing methods. The most important changes include adding
true division functionality for BigDecimal, modifying scaling methods,
and updating the handling of leading zeros in BigUInt operations.
Notably, this PR fixes a bug in `BigUInt.multiply` where the carry is
mistakenly skipped if a word of x2 is zero.
### BigDecimal Enhancements:
* Added `true_divide` function to perform division with specified
precision and rounding rules in
`src/decimojo/bigdecimal/arithmetics.mojo`.
* Updated the benchmarks to include the new division operation in
`benches/bigdecimal/bench.mojo`.
[[1]](diffhunk://#diff-96175f1000f81fe074f70a9adc4b39cd3f2dac8e85d30aa7efed9fc02b46e5ecR4)
[[2]](diffhunk://#diff-96175f1000f81fe074f70a9adc4b39cd3f2dac8e85d30aa7efed9fc02b46e5ecR16)
[[3]](diffhunk://#diff-96175f1000f81fe074f70a9adc4b39cd3f2dac8e85d30aa7efed9fc02b46e5ecR29-R35)
### BigUInt Improvements:
* Replaced `remove_trailing_zeros` with `remove_leading_empty_words` to
handle leading zeros more effectively in multiple functions across
`src/decimojo/biguint/arithmetics.mojo`.
[[1]](diffhunk://#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL180-R180)
[[2]](diffhunk://#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL275-R271)
[[3]](diffhunk://#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL383-R373)
[[4]](diffhunk://#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL964-R827)
[[5]](diffhunk://#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL1032-R895)
* Simplified the `divmod` function to use `floor_divide` and `subtract`
for quotient and remainder calculation in
`src/decimojo/biguint/arithmetics.mojo`.
### Codebase Simplification:
* Renamed `multiply_by_power_of_10` to `scale_up_by_power_of_10` for
clarity and consistency in `src/decimojo/biguint/arithmetics.mojo`.
* Removed unnecessary cases and optimized the `floor_divide` function in
`src/decimojo/biguint/arithmetics.mojo`.
[[1]](diffhunk://#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL338-L343)
[[2]](diffhunk://#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL358-R348)
These changes enhance the arithmetic capabilities of BigDecimal and
BigUInt, improve code clarity, and ensure more efficient handling of
numerical operations.
1 parent e5cc073 commit 8389aa3
File tree
8 files changed
+1495
-346
lines changed- benches/bigdecimal
- src/decimojo
- bigdecimal
- biguint
- tests/bigdecimal
- test_data
8 files changed
+1495
-346
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
| 35 | + | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
| |||
0 commit comments