[integer] Implement floor_divide_by_power_of_billion()
#115
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 introduces several updates to the
decimojolibrary, focusing on improving numerical operations withBigUIntandBigDecimaltypes. Key changes include replacing a placeholder function with a more optimized implementation, adding debug assertions to enforce non-negative input constraints, and introducing a new utility function for division by powers of a billion.Improvements to numerical operations:
Optimized division by powers of a billion: Replaced the placeholder call to
floor_divide_by_power_of_tenwith the newly implementedfloor_divide_by_power_of_billionintrue_divide_fastfor better performance.New utility function: Added
floor_divide_by_power_of_billion, which efficiently removes the lastnwords of aBigUInt, equivalent to dividing by(10^9)^n. This function handles edge cases and includes debug assertions.Input validation and robustness:
Debug assertions for non-negative inputs: Added debug assertions to ensure that input parameters
nare non-negative in functions such asmultiply_by_power_of_ten,multiply_inplace_by_power_of_ten,multiply_by_power_of_billion,multiply_inplace_by_power_of_billion, andfloor_divide_by_power_of_ten. These assertions improve code reliability during development and testing.Updated handling of zero or negative
n: Modified behavior in several functions to return the input unchanged whenn <= 0, ensuring consistent and predictable results.These changes collectively enhance the library's performance, robustness, and maintainability.