Skip to content

DeciMojo v0.5.0

Choose a tag to compare

@forfudan forfudan released this 06 Aug 20:13
· 71 commits to main since this release
02da4dc

20250806 (v0.5.0)

DeciMojo v0.5.0 introduces significant enhancements to the BigDecimal and BigUInt types, including new mathematical functions and performance optimizations. The release adds trigonometric functions for BigDecimal, implements the Chudnovsky algorithm for computing π, and implements the Karatsuba multiplication algorithm and Burnikel-Ziegler division algorithm for BigUInt. In-place operations, slice operations, and SIMD operations are now supported for BigUInt arithmetic. The Decimal type is renamed to Decimal128 to reflect its 128-bit fixed precision. The release also includes improved error handling, optimized type conversions, refactored testing suites, and documentation updates.

DeciMojo v0.5.0 is compatible with Mojo v25.5.

⭐️ New

  1. Introduce trigonometric functions for BigDecimal: sin(), cos(), tan(), cot(), csc(), sec(). These functions compute the corresponding trigonometric values of a given angle in radians with arbitrary precision (#96, #99).
  2. Introduce the function pi() for BigDecimal to compute the value of π (pi) with arbitrary precision with the Chudnovsky algorithm with binary splitting (#95).
  3. Implement the sqrt() function for BigUInt to compute the square root of a BigUInt number as a BigUInt object (#107).
  4. Introduce a DeciMojoError type and various aliases to handle errors in DeciMojo. This enables a more consistent error handling mechanism across the library and allows users to track errors more easily (#114).

🦋 Changed

Changes in BigUInt:

  1. Refine the BigUInt multiplication with the Karatsuba algorithm. The time complexity of maltiplication is reduced from $O(n^2)$ to $O(n^{ln(3/2)})$ for large integers, which significantly improves performance for big numbers. Doubling the size of the numbers will only increase the time taken by a factor of about 3, instead of 4 as in the previous implementation (#97).
  2. Refine the BigUInt division with the Burnikel-Ziegler fast recursive division algorithm. The time complexity of division is also reduced from $O(n^2)$ to $O(n^{ln(3/2)})$ for large integers (#103).
  3. Refine the fall-back schoolbook division of BigUInt to improve performance. The fallback division is used when the divisor is small enough (#98, #100).
  4. Implement auxiliary functions for arithmetic operations of BigUInt to handle special cases more efficiently, e.g., when the second operand is one-word long or is a UInt32 value (#98, #104, #111).
  5. Implement in-place subtraction for BigUInt. The __isub__ method of BigUInt will now conduct in-place subtraction. x -= y will not lead to memory allocation, but will modify the original BigUInt object x directly (#98).
  6. Use SIMD for BigUInt addition and subtraction operations. This allows the addition and subtraction of two BigUInt objects to be performed in parallel, significantly improving performance for large numbers (#101, #102).
  7. Implement functions for all arithmetic operations on slices of BigUInt objects. This allows you to perform arithmetic operations on slices of BigUInt objects without having to convert them to BigUInt first, leading to less memory allocation and improved performance (#105).
  8. Add to_uint64() and to_uint128() methods to BigUInt to for fast type conversion (#91).

Changes in BigDecimal:

  1. Re-implemente the sqrt() function for BigDecimal to use the new BigUInt.sqrt() method for better performance and accuracy. The new implementation adjusts the scale and coefficient directly, which is more efficient than the previous method. Introduce a new sqrt_decimal_approach() function to preserve the old implementation for reference (#108).
  2. Refine or re-implement the basic arithmetic operations, e.g.,, addition, subtraction, multiplication, division, etc, for BigDecimal and simplify the logic. The new implementation is more efficient and easier to understand, leading to better performance (#109, #110).
  3. Add a default precision 36 for BigDecimal methods (#112).

Other changes:

  1. Update the codebase to Mojo v25.5 (#113).
  2. Remove unnecessary raises keywords for all functions (#92).
  3. Rename the Decimal type to Decimal128 to reflect its fixed precision of 128 bits. It has a new alias Dec128 (#112).
  4. Decimal is now an alias for BigDecimal (#112).

🛠️ Fixed

  • Fix a bug for BigUInt comparison: When there are leading zero words, the comparison returns incorrect results (#97).
  • Fix the is_zero(), is_one(), and is_two() methods for BigUInt to correctly handle the case when there are leading zero words (#97).

📚 Documentation and testing

  • Refactor the test files for BigDecimal (PR #93).
  • Refactor the test files for BigInt (PR #106).

What's Changed

  • [integer] Improve the BigUInt type with several changes by @forfudan in #91
  • [integer][decimal] Improve error messages and remove unnecessary raises by @forfudan in #92
  • [tests] Refactor the test files for BigDecimal by @forfudan in #93
  • [decimal] Implement arctan() and pi() for BigDecimal by @forfudan in #94
  • [decimal] Use Chudnovsky with binary splitting to calculate pi by @forfudan in #95
  • [decimal] Implement sin() and cos() for BigDecimal by @forfudan in #96
  • [integer] Improve BigUInt multiplication by implementing Karatsuba algorithm by @forfudan in #97
  • [integer] Refine arithmetic functions of BigUInt by @forfudan in #98
  • [decimal] Implement tan(), cot(), csc(), sec() for BigDecimal by @forfudan in #99
  • [integer] Refine normalization of BigUInt division so that correction is no longer needed by @forfudan in #100
  • [integer] Optimize BigUInt addition and subtraction with SIMD and early stop tricks by @forfudan in #101
  • [integer] Improve BigUInt subtraction with SIMD by @forfudan in #102
  • [integer] Implement Burnikel-Ziegler fast recursive division algorithm for BigUInt by @forfudan in #103
  • [integer] Update multiply_inplace_by_uint32() for BigUInt when the y is no greater than 4 by @forfudan in #104
  • [integer] Use slices operations on BigUInt fast division algorithm by @forfudan in #105
  • [tests] Refactor the testing files for BigInt and BigUInt by @forfudan in #106
  • [integer] Implement sqrt() for BigUInt by @forfudan in #107
  • [decimal] Re-implement BigDecimal.sqrt() with help of BigUInt.sqrt() by @forfudan in #108
  • [decimal] Refine methods of BigDecimal type by @forfudan in #109
  • [decimal] Re-implement the true_divide() function for BigDecimal by @forfudan in #110
  • [integer] Update BigUInt division by simplifying logic and adding auxiliary functions by @forfudan in #111
  • [decimal] Rename Decimal as Decimal128 + Add default precision to BigDecimal as 36 by @forfudan in #112
  • [mojo] Update the codebase to Mojo v25.5 nightly by @forfudan in #113
  • [errors] Improve error handling by using DeciMojoError type by @forfudan in #114
  • [integer] Implement floor_divide_by_power_of_billion() by @forfudan in #115
  • [integer] Ensure that BigUInt has no leading zero words by @forfudan in #116
  • [docs] Update the changelog for version 0.5.0 by @forfudan in #117
  • [release][docs] Update documents for the release of version 0.5.0 by @forfudan in #118

Full Changelog: v0.4.1...v0.5.0