[integer] Refine normalization of BigUInt division so that correction is no longer needed
#100
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request focuses on optimizing arithmetic operations for
BigUIntin thedecimojolibrary. The changes primarily involve replacing hardcoded constants (e.g.,1_000_000_000) with theBigUInt.BASEandBigUInt.BASE_MAXproperties, introducing in-place scaling methods, and improving normalization logic for division operations. These updates enhance code maintainability, readability, and performance.Division improvements:
floor_divideby introducing a table-based lookup for determining the number of digits to shift, improving quotient estimation accuracy. ([src/decimojo/biguint/arithmetics.mojoL931-R1037](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL931-R1037))floor_divide_generalto prevent infinite loops during quotient estimation. ([src/decimojo/biguint/arithmetics.mojoL991-R1098](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL991-R1098))Updates to scaling methods:
scale_up_by_power_of_10andscale_up_by_power_of_billionwith their in-place equivalents (scale_up_inplace_by_power_of_10andscale_up_inplace_by_power_of_billion) across multiple functions, reducing redundant object creation. ([[1]](https://github.com/forfudan/decimojo/pull/100/files#diff-f79534f4e7fdd891932ce9d015c50bd3c8a72c4a1689f0cb55524490ffc0458dL281-R281),[[2]](https://github.com/forfudan/decimojo/pull/100/files#diff-f79534f4e7fdd891932ce9d015c50bd3c8a72c4a1689f0cb55524490ffc0458dL385-R385),[[3]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL621-R621),[[4]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL640-R640),[[5]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL700-R701),[[6]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL807-R880),[[7]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL991-R1098))Transition to
BigUInt.BASEandBigUInt.BASE_MAX:1_000_000_000and999_999_999withBigUInt.BASEandBigUInt.BASE_MAXin arithmetic operations (e.g., addition, subtraction, multiplication, division) to improve flexibility and reduce magic numbers. ([[1]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL204-R205),[[2]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL231-R236),[[3]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL260-R261),[[4]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL274-R274),[[5]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL330-R330),[[6]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL372-R372),[[7]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL531-R532),[[8]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL728-L735),[[9]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL782-R863),[[10]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL916-R986),[[11]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL1063-R1176),[[12]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL1090-R1185),[[13]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL1111-R1206),[[14]](https://github.com/forfudan/decimojo/pull/100/files#diff-95a5c66e5957fff2a2a8a2710ffb11a4ad7d0bddaf3bc11d075d62ddaa8b915cL1136-R1231))