decimojo

DeciMojo changelog

This is a list of RELEASED changes for the DeciMojo Package.

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

📚 Documentation and testing

20250701 (v0.4.1)

Version 0.4.1 of DeciMojo introduces implicit type conversion between built-in integral types and arbitrary-precision types.

⭐️ New

Now DeciMojo supports implicit type conversion between built-in integeral types (Int, UInt, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128,UInt128, Int256, and UInt256) and the arbitrary-precision types (BigUInt, BigInt, and BigDecimal). This allows you to use these built-in types directly in arithmetic operations with BigInt and BigUInt without explicit conversion. The merged type will always be the most compatible one (PR #89, PR #90).

For example, you can now do the following:

from decimojo.prelude import *

fn main() raises:
    var a = BInt(Int256(-1234567890))
    var b = BigUInt(31415926)
    var c = BDec("3.14159265358979323")

    print("a =", a)
    print("b =", b)
    print("c =", c)

    print(a * b)  # Merged to BInt
    print(a + c)  # Merged to BDec
    print(b + c)  # Merged to BDec
    print(a * Int(-128))  # Merged to BInt
    print(b * UInt(8))  # Merged to BUInt
    print(c * Int256(987654321123456789))  # Merged to BDec

    var lst = [a, b, c, UInt8(255), Int64(22222), UInt256(1234567890)]
    # The list is of the type `List[BigDecimal]`
    for i in lst:
        print(i, end=", ")

Running the code will give your the following results:

a = -1234567890
b = 31415926
c = 3.14159265358979323
-38785093474216140
-1234567886.85840734641020677
31415929.14159265358979323
158024689920
251327408
3102807559527666386.46423202534973847
-1234567890, 31415926, 3.14159265358979323, 255, 22222, 1234567890,

🦋 Changed

Optimize the case when you increase the value of a BigInt object in-place by 1, i.e., i += 1. This allows you to iterate faster (PR #89). For example, we can compute the time taken to iterate from 0 to 1_000_000 using BigInt and compare it with the built-in Int type:

from decimojo.prelude import *

fn main() raises:
    i = BigInt(0)
    end = BigInt(1_000_000)
    while i < end:
        print(i)
        i += 1
scenario Time taken
v0.4.0 BigInt 1.102s
v0.4.1 BigInt 0.912s
Built-in Int 0.893s

🛠️ Fixed

Fix a bug in BigDecimal where it cannot create a correct value from a integral scalar, e.g., BDec(UInt16(0)) returns an unitialized BigDecimal object (PR #89).

📚 Documentation and testing

Update the tests module and refactor the test files for BigUInt (PR #88).

20250625 (v0.4.0)

DeciMojo v0.4.0 updates the codebase to Mojo v25.4. This release enables you to use DeciMojo with the latest Mojo features.

20250606 (v0.3.1)

DeciMojo v0.3.1 updates the codebase to Mojo v25.3 and replaces the magic package manager with pixi. This release enables you to use DeciMojo with the latest Mojo features and the new package manager.

20250415 (v0.3.0)

DeciMojo v0.3.0 introduces the arbitrary-precision BigDecimal type with comprehensive arithmetic operations, comparisons, and mathematical functions (sqrt, root, log, exp, power). A new tomlmojo package supports test refactoring. Improvements include refined BigUInt constructors, enhanced scale_up_by_power_of_10() functionality, and a critical multiplication bug fix.

⭐️ New

🦋 Changed

🛠️ Fixed

20250401 (v0.2.0)

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.

⭐️ New

🦋 Changed

❌ Removed

🛠️ Fixed

📚 Documentation and testing