Commit 053934d
authored
This pull request introduces significant enhancements to the
`BigDecimal` module, focusing on trigonometric functionality, precision
handling, and modular arithmetic. It also updates documentation and test
cases to support these changes. The most important changes include the
addition of `sin` and `cos` functions, improvements to rounding
precision methods, and modular arithmetic support.
### Trigonometric Functionality Enhancements:
* Added `sin` and `cos` functions to `struct BigDecimal`, with range
reduction and Taylor series implementations for accurate calculations.
These functions handle edge cases for π-related values and ensure high
precision. (`src/decimojo/bigdecimal/bigdecimal.mojo`
[src/decimojo/bigdecimal/bigdecimal.mojoR765-R774](diffhunk://#diff-be2f9b2702fd15952546e17fe94a64c22902a0e4678bfd9cb925269647923db4R765-R774),
`src/decimojo/bigdecimal/trigonometric.mojo` F4fb1110L30R321)
* Updated `arctan` function to use `round_to_precision` for consistent
precision handling and added intermediate result handling for better
readability. (`src/decimojo/bigdecimal/trigonometric.mojo`
F4fb1110L56R355)
### Precision Handling Improvements:
* Replaced `round` with `round_to_precision` across multiple functions,
adding options to remove extra digits due to rounding and prevent
trailing zeros. (`src/decimojo/bigdecimal/constants.mojo`
F7b2c265L166R322, `src/decimojo/bigdecimal/rounding.mojo`
[src/decimojo/bigdecimal/rounding.mojoL102-R104](diffhunk://#diff-2d08304d5c7273c47523b98f68714e1c980a59b7c4f0a9bf444ffca9435afa17L102-R104))
* Added detailed notes in the `round_to_precision` method to clarify the
behavior of precision-related parameters.
(`src/decimojo/bigdecimal/bigdecimal.mojo`
[src/decimojo/bigdecimal/bigdecimal.mojoR848-R854](diffhunk://#diff-be2f9b2702fd15952546e17fe94a64c22902a0e4678bfd9cb925269647923db4R848-R854))
### Modular Arithmetic Support:
* Introduced the `__mod__` method in `struct BigDecimal` to support
modulo operations, leveraging `truncate_modulo`.
(`src/decimojo/bigdecimal/bigdecimal.mojo`
[src/decimojo/bigdecimal/bigdecimal.mojoR526-R534](diffhunk://#diff-be2f9b2702fd15952546e17fe94a64c22902a0e4678bfd9cb925269647923db4R526-R534))
### Documentation Updates:
* Expanded documentation in `docs/internal_notes.md` to include examples
and precision comparisons for `sin` functionality, highlighting
discrepancies between Decimojo, WolframAlpha, and `mpmath`.
(`docs/internal_notes.md`
[docs/internal_notes.mdL5-R16](diffhunk://#diff-6da6b2e1a170d4269cd7863de3fd61fd4098c67fc788deb68bbe6f0f18b98d24L5-R16))
### Test Case Enhancements:
* Refactored trigonometric tests to include `sin` and `arctan`
functions, enabling modular test execution through a reusable `run_test`
function. (`tests/bigdecimal/test_bigdecimal_trigonometric.mojo`
[tests/bigdecimal/test_bigdecimal_trigonometric.mojoL14-R45](diffhunk://#diff-e8f272193f827af6eee86da91ce756ed1739f4e178b6a5c19c1d10165d7fd17aL14-R45))
1 parent b9c526e commit 053934d
9 files changed
Lines changed: 542 additions & 46 deletions
File tree
- docs
- src/decimojo/bigdecimal
- tests/bigdecimal
- test_data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
105 | 123 | | |
106 | 124 | | |
107 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
30 | 48 | | |
31 | 49 | | |
32 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
6 | 17 | | |
7 | 18 | | |
8 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
526 | 535 | | |
527 | 536 | | |
528 | 537 | | |
| |||
753 | 762 | | |
754 | 763 | | |
755 | 764 | | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
756 | 775 | | |
757 | 776 | | |
758 | 777 | | |
| |||
826 | 845 | | |
827 | 846 | | |
828 | 847 | | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
829 | 855 | | |
830 | 856 | | |
831 | 857 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
170 | 177 | | |
171 | 178 | | |
172 | 179 | | |
| |||
212 | 219 | | |
213 | 220 | | |
214 | 221 | | |
215 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
216 | 229 | | |
217 | 230 | | |
218 | 231 | | |
| |||
309 | 322 | | |
310 | 323 | | |
311 | 324 | | |
312 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
104 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
0 commit comments