DeciMojo v0.5.0
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
- 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). - Introduce the function
pi()forBigDecimalto compute the value of π (pi) with arbitrary precision with the Chudnovsky algorithm with binary splitting (#95). - Implement the
sqrt()function forBigUIntto compute the square root of aBigUIntnumber as aBigUIntobject (#107). - Introduce a
DeciMojoErrortype 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:
- Refine the
BigUIntmultiplication 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). - Refine the
BigUIntdivision 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). - Refine the fall-back schoolbook division of
BigUIntto improve performance. The fallback division is used when the divisor is small enough (#98, #100). - Implement auxiliary functions for arithmetic operations of
BigUIntto handle special cases more efficiently, e.g., when the second operand is one-word long or is aUInt32value (#98, #104, #111). - Implement in-place subtraction for
BigUInt. The__isub__method ofBigUIntwill now conduct in-place subtraction.x -= ywill not lead to memory allocation, but will modify the originalBigUIntobjectxdirectly (#98). - Use SIMD for
BigUIntaddition and subtraction operations. This allows the addition and subtraction of twoBigUIntobjects to be performed in parallel, significantly improving performance for large numbers (#101, #102). - Implement functions for all arithmetic operations on slices of
BigUIntobjects. This allows you to perform arithmetic operations on slices ofBigUIntobjects without having to convert them toBigUIntfirst, leading to less memory allocation and improved performance (#105). - Add
to_uint64()andto_uint128()methods toBigUIntto for fast type conversion (#91).
Changes in BigDecimal:
- Re-implemente the
sqrt()function forBigDecimalto use the newBigUInt.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 newsqrt_decimal_approach()function to preserve the old implementation for reference (#108). - Refine or re-implement the basic arithmetic operations, e.g.,, addition, subtraction, multiplication, division, etc, for
BigDecimaland simplify the logic. The new implementation is more efficient and easier to understand, leading to better performance (#109, #110). - Add a default precision 36 for
BigDecimalmethods (#112).
Other changes:
- Update the codebase to Mojo v25.5 (#113).
- Remove unnecessary
raiseskeywords for all functions (#92). - Rename the
Decimaltype toDecimal128to reflect its fixed precision of 128 bits. It has a new aliasDec128(#112). Decimalis now an alias forBigDecimal(#112).
🛠️ Fixed
- Fix a bug for
BigUIntcomparison: When there are leading zero words, the comparison returns incorrect results (#97). - Fix the
is_zero(),is_one(), andis_two()methods forBigUIntto correctly handle the case when there are leading zero words (#97).
📚 Documentation and testing
What's Changed
- [integer] Improve the
BigUInttype with several changes by @forfudan in #91 - [integer][decimal] Improve error messages and remove unnecessary
raisesby @forfudan in #92 - [tests] Refactor the test files for
BigDecimalby @forfudan in #93 - [decimal] Implement
arctan()andpi()forBigDecimalby @forfudan in #94 - [decimal] Use Chudnovsky with binary splitting to calculate pi by @forfudan in #95
- [decimal] Implement
sin()andcos()forBigDecimalby @forfudan in #96 - [integer] Improve
BigUIntmultiplication by implementing Karatsuba algorithm by @forfudan in #97 - [integer] Refine arithmetic functions of
BigUIntby @forfudan in #98 - [decimal] Implement
tan(),cot(),csc(),sec()forBigDecimalby @forfudan in #99 - [integer] Refine normalization of
BigUIntdivision so that correction is no longer needed by @forfudan in #100 - [integer] Optimize
BigUIntaddition and subtraction with SIMD and early stop tricks by @forfudan in #101 - [integer] Improve
BigUIntsubtraction with SIMD by @forfudan in #102 - [integer] Implement Burnikel-Ziegler fast recursive division algorithm for
BigUIntby @forfudan in #103 - [integer] Update
multiply_inplace_by_uint32()forBigUIntwhen the y is no greater than 4 by @forfudan in #104 - [integer] Use slices operations on
BigUIntfast division algorithm by @forfudan in #105 - [tests] Refactor the testing files for
BigIntandBigUIntby @forfudan in #106 - [integer] Implement
sqrt()forBigUIntby @forfudan in #107 - [decimal] Re-implement
BigDecimal.sqrt()with help ofBigUInt.sqrt()by @forfudan in #108 - [decimal] Refine methods of
BigDecimaltype by @forfudan in #109 - [decimal] Re-implement the
true_divide()function forBigDecimalby @forfudan in #110 - [integer] Update
BigUIntdivision by simplifying logic and adding auxiliary functions by @forfudan in #111 - [decimal] Rename
DecimalasDecimal128+ Add default precision toBigDecimalas 36 by @forfudan in #112 - [mojo] Update the codebase to Mojo v25.5 nightly by @forfudan in #113
- [errors] Improve error handling by using
DeciMojoErrortype by @forfudan in #114 - [integer] Implement
floor_divide_by_power_of_billion()by @forfudan in #115 - [integer] Ensure that
BigUInthas 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