DeciMojo v0.2 for Mojo 25.2 - decimal and integer mathematics library

For more information, please visit the repo of DeciMojo: https://github.com/forfudan/decimojo

Version 0.2.0 marks a significant expansion of DeciMojo with the introduction of BigInt and BigUInt types, providing unlimited precision integer arithmetic to complement the existing fixed-precision Decimal type. Core arithmetic functions for the Decimal type have been completely rewritten using Mojo 25.2’s UInt128, delivering substantial performance improvements. This release also extends mathematical capabilities with advanced operations including logarithms, exponentials, square roots, and n-th roots for the Decimal type. The codebase has been reorganized into a more modular structure, enhancing maintainability and extensibility. With comprehensive test coverage, improved documentation in multiple languages, and optimized memory management, v0.2.0 represents a major advancement in both functionality and performance for numerical computing in Mojo.

:star: New

  • Add BigInt and BigUInt implementation with unlimited precision integer arithmetic.
  • Implement full arithmetic operations for BigInt and BigUInt: addition, subtraction, multiplication, division, modulo and power operations.
  • Support both floor division (round toward negative infinity) and truncate division (round toward zero) semantics for mathematical correctness.
  • Add complete comparison operations for BigInt with proper handling of negative values.
  • Implement efficient string representation and parsing for BigInt and BigUInt.
  • Add advanced mathematical operations for Decimal: square root and n-th root.
  • Add logarithm functions for Decimal: natural logarithm, base-10 logarithm, and logarithm with arbitrary base.
  • Add exponential function and power function with arbitrary exponents for Decimal.

:butterfly: Changed

  • Completely re-write the core arithmetic functions for Decimal type using UInt128 introduced in Mojo 25.2. This significantly improves the performance of Decimal operations.
  • Improve memory management system to reduce allocations during calculations.
  • Reorganize codebase with modular structure (decimal, arithmetics, comparison, exponential).
  • Enhance Decimal comparison operators for better handling of edge cases.
  • Update internal representation of Decimal for better precision handling.

:cross_mark: Removed

  • Remove deprecated legacy string formatting methods.
  • Remove redundant conversion functions that were replaced with a more unified API.

:hammer_and_wrench: Fixed

  • Fix edge cases in division operations with zero and one.
  • Correct sign handling in mixed-sign operations for both Decimal.
  • Fix precision loss in repeated addition/subtraction operations.
  • Correct rounding behavior in edge cases for financial calculations.
  • Address inconsistencies between operator methods and named functions.

:books: Documentation and testing

  • Add comprehensive test suite for BigInt and BigUInt with over 200 test cases covering all operations and edge cases.
  • Create detailed API documentation for both Decimal and BigInt.
  • Add performance comparison benchmarks between DeciMojo and Python’s decimal/int implementation.
  • Update multi-language documentation to include all new functionality (English and Chinese).
  • Include clear explanations of division semantics and other potentially confusing numerical concepts.
3 Likes

Wow, awesome work. Very excited to see a BigInt type here!

1 Like

Thanks! BigInt is quite important in many situations.