Skip to content

Conversation

@forfudan
Copy link
Owner

This pull request introduces significant enhancements and optimizations to the BigDecimal benchmarking and arithmetic operations in the decimojo library. Key changes include the addition of new test cases for handling very large numbers, improvements in precision handling, and code simplifications for arithmetic operations. Below is a summary of the most important changes grouped by theme:

Code Simplifications and refinement

  • Arithmetic Operations: Simplified add and subtract functions in src/decimojo/bigdecimal/arithmetics.mojo by replacing explicit variable creation with in-place operations (+= and -=). This reduces redundancy and improves code clarity.
  • Refine and simplify scale_up() method and add a scale_up_inplace() method.

Alias Updates

  • Aliases for BigDecimal: Removed the BigDec alias and introduced a lowercase alias bdec for consistency and improved readability.

Benchmark Enhancements

  • Addition Benchmarks: Expanded the number of test cases from 50 to 60, including 10 cases with very large numbers (1000+ digits). Added specific scenarios like Fibonacci-like patterns, extreme scale differences, and scientific notation.
  • Division Benchmarks: Introduced six new test cases for large-scale division, ranging from 1024 to 32768 words. Adjusted logging to truncate long numbers for better readability.

Precision Handling

  • Dynamic Precision: Increased Python's decimal precision to handle very large numbers (up to 10000 digits for addition and 4096 digits for division). Updated logging to reflect dynamic precision limits for both Python and Mojo implementations.

Logging Improvements

  • Result Comparison: Added detailed result verification and warnings for mismatches in both addition and division benchmarks. Truncated long results in logs for better readability.

@forfudan forfudan merged commit 7a5101b into main Jul 17, 2025
1 check passed
@forfudan forfudan deleted the work branch July 17, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants