Skip to content

Releases: forfudan/decimo

Decimo v0.9.0

23 Mar 19:42

Choose a tag to compare

20260323 (v0.9.0)

Decimo v0.9.0 updates the codebase to Mojo v0.26.2 and marks the "make it useful" phase. This release introduces three major additions:

First, a full-featured CLI arbitrary-precision calculator (decimo), powered by Decimo's BigDecimal. It includes a complete tokenizer, a shunting-yard parser, and an RPN evaluator with working-precision guard digits, supporting built-in mathematical functions (sqrt, cbrt, root, ln, log, log10, exp, trigonometric functions, abs), constants (pi, e), and configurable output formatting (scientific/engineering notation, digit delimiters, rounding modes, and precision control).

Second, the BigDecimal API is significantly expanded with methods aligned to Python's decimal.Decimal and the IEEE 754 specification, including as_tuple(), adjusted(), same_quantum(), scaleb(), fma(), copy_abs(), copy_negate(), copy_sign(), bit_count(), __float__(), engineering notation, and digit-group delimiters for to_string(). The ROUND_HALF_DOWN rounding mode is added, bringing the total to seven.

Third, Decimo gains Python bindings via Mojo's PythonModuleBuilder, exposing BigDecimal as a native Python extension module (_decimo.so) with a Pythonic Decimal wrapper for seamless interoperability.

⭐️ New in v0.9.0

CLI Calculator:

  1. Implement an arbitrary-precision CLI calculator with tokenizer, shunting-yard parser, and RPN evaluator, supporting arithmetic expressions with parentheses and operator precedence (PR #170).
  2. Add built-in functions (sqrt, cbrt, root, ln, log, log10, exp, sin, cos, tan, cot, csc, abs), constants (pi, e), and configurable output formatting (scientific/engineering notation, digit delimiter, padding, rounding mode) (PR #171).
  3. Improve CLI error handling with token location tracing and ANSI-coloured diagnostic output (PR #178).
  4. Use working precision (user precision + guard digits) for intermediate calculations to improve result accuracy (PR #182).

BigDecimal:

  1. Add engineering notation (to_eng_string()) and digit-group delimiters (to_string_with_separators()) to to_string(), with optional line-width wrapping (PR #172).
  2. Add utility methods: is_integer(), is_signed(), number_class(), logb(), normalize(), radix() (PR #173).
  3. Implement as_tuple() returning (sign, digits, exponent), matching Python's Decimal.as_tuple() (PR #174).
  4. Implement adjusted(), copy_abs(), copy_negate(), and copy_sign() aligned with Python's decimal API (PR #176).
  5. Implement same_quantum() and add the ROUND_HALF_DOWN rounding mode, bringing the total to seven (PR #177).
  6. Implement scaleb(), fma(), bit_count(), and __float__() (implements FloatableRaising) (PR #183).

Python Bindings:

  1. Implement Python bindings via Mojo's PythonModuleBuilder, exposing BigDecimal as a native extension module _decimo.so with arithmetic, comparison, and string operations (PR #179).
  2. Restructure python/ to a src layout with pyproject.toml for PyPI packaging (PR #180).

🦋 Changed in v0.9.0

  1. Update the codebase to Mojo v0.26.2, adopting byte= slicing syntax, out parameter convention for constructors, and updated String/StringSlice APIs (PR #185).
  2. Merge TOMLMojo into Decimo as the sub-package decimo.toml, removing standalone packaging (PR #181).
  3. Rename exponent() to adjusted() for BigDecimal to align with Python's decimal module naming (PR #176).
  4. Change default precision of BigDecimal to 28 significant digits, matching Python's decimal module default.
  5. Remove deprecated free-function comparison aliases and legacy method names from BigDecimal (PR #173).
  6. Align print_internal_representation() output style across BigInt, BigUInt, BigDecimal, and Decimal128 with dynamic column alignment (PR #169).

📚 Documentation and testing in v0.9.0

  • Add comprehensive user manuals for the Decimo library and the CLI calculator (PR #184).
  • Add info badges to the README file.

Decimo v0.8.0

25 Feb 20:06

Choose a tag to compare

20260225 (v0.8.0)

Library renamed from decimojo to decimo. The package name, import path, and all public references have been updated.

Decimo v0.8.0 is a profound milestone in the development of Decimo, marking the "make it fast" phase. There are two major improvements in this release:

First, it introduces a completely new BigInt (BInt) type using a base-2^32 internal representation. This replaces the previous base-10^9 implementation (now available as BigInt10) with a little-endian format using UInt32 words, dramatically improving the performance of all integer operations. The new BigInt implements the Karatsuba multiplication algorithm and the Burnikel-Ziegler division algorithm for sub-quadratic performance on large integers, and includes divide-and-conquer base conversion for fast string I/O. It also adds bitwise operations, GCD and modular arithmetic, and an optimized integer square root. Benchmarks show that the new BigInt outperforms Python's built-in int type in most cases, with up to 11× speedup for power operations and 5× for shift operations.

Second, it optimizes the mathematical operations for BigDecimal, bringing significant performance and accuracy improvements. The sqrt() function is re-implemented using the reciprocal square root method combined with Newton's method for faster convergence. The ln() function now supports an atanh-based approach with mathematical constant caching via MathCache. The exp() function benefits from aggressive range reduction for much faster convergence. The root() function gains rational root decomposition and a direct Newton method. The to_string() method is aligned with CPython's decimal module formatting rules for scientific notation and trailing zeros. The BigUInt layer also gains the Toom-Cook 3-way multiplication algorithm. Benchmarks indicate that BigDecimal operations beat Python's decimal module in speed, especially for high-precision calculations (e.g., division up to 915× faster, sqrt 3.5× faster on average).

⭐️ New in v0.8.0

BigInt (base-2^32):

  1. Implement the BigInt (BInt) type using a base-2^32 internal representation with little-endian UInt32 words. This is a completely new implementation optimized for binary computations while supporting arbitrary precision (PR #133, #134, #135, #141).
  2. Implement the Karatsuba multiplication algorithm for BigInt, reducing time complexity from $O(n^2)$ to $O(n^{\log_2 3})$ for large integers (PR #142).
  3. Implement the slice-based Burnikel-Ziegler division algorithm for BigInt, providing sub-quadratic division performance for the base-2^32 representation (PR #144).
  4. Implement divide-and-conquer base conversion for BigInt.to_string(), significantly improving string conversion speed for large integers (PR #145).
  5. Implement bitwise operations (__and__, __or__, __xor__, __lshift__, __rshift__, __invert__) and true in-place bitwise operations for BigInt (PR #150, #151).
  6. Implement gcd(), extended_gcd(), mod_inverse(), and mod_pow() for BigInt, providing number-theoretic functions (PR #152, #153).
  7. Implement an optimized sqrt() for BigInt using Newton's method with a good initial approximation, delivering 1.39× average speedup over Python (PR #155).

BigDecimal:

  1. Implement the quantize() function for BigDecimal to format decimal numbers to a specified number of decimal places, similar to Python's Decimal.quantize() (PR #126).
  2. Implement true in-place arithmetic functions (__iadd__, __isub__, __imul__) for BigDecimal to reduce memory allocations during repeated operations (PR #162).
  3. Implement methods to initialize BigInt and BigDecimal from Python objects, enabling seamless interoperability with Python's int and decimal.Decimal (PR #129).

Core:

  1. Add ROUND_CEILING and ROUND_FLOOR rounding modes to RoundingMode, bringing the total to six modes (PR #164).

TOMLMojo:

  1. Implement all core TOML v1.0 specification features for TOMLMojo, including inline tables, arrays of tables, dotted keys, multiline strings, and all value types (PR #140).

🦋 Changed in v0.8.0

BigInt:

  1. Rename the previous base-10^9 BigInt to BigInt10. The alias BInt now refers to the new base-2^32 BigInt type (PR #143, #154).
  2. Optimize from_string() for BigInt with an improved string parser and divide-and-conquer approach for fast base conversion (PR #146, #147, #148).
  3. Optimize to_string() for BigInt with divide-and-conquer base conversion, achieving 6× average speedup over Python (PR #149).

BigDecimal:

  1. Re-implement sqrt() for BigDecimal using the reciprocal square root method combined with Newton's method, delivering faster convergence and better accuracy for high-precision calculations (PR #163).
  2. Optimize ln() and exp() for BigDecimal with mathematical constant caching via MathCache and improved handling of one-word dividends (PR #160).
  3. Apply aggressive range reduction for exp() to achieve faster convergence at high precision (PR #167).
  4. Implement direct Newton method for general root() calculation, replacing the previous iterative approach (PR #161).
  5. Add rational root decomposition to root() and an atanh-based approach to ln() for improved accuracy and convergence (PR #168).
  6. Optimize true_divide_general() to correctly account for existing word surplus in the dividend (PR #158).
  7. Optimize division with truncation and align to_string() output with CPython's decimal module formatting for scientific notation and trailing zeros (PR #165).

BigUInt:

  1. Implement the Toom-Cook 3-way multiplication algorithm for BigUInt, improving performance for large number multiplications (PR #166).
  2. Unify and refine initialization methods for BigUInt with consistent constructors and improved validation (PR #127, #128, #131).

Core:

  1. Improve naming consistency between types, ensuring uniform method names across BigInt, BigDecimal, and Decimal128 (PR #164).
  2. Make RoundingMode type implicitly copyable for easier usage in function signatures (PR #125).

🛠️ Fixed in v0.8.0

  • Fix string formatting for BigDecimal to match Python's decimal module formatting rules, including correct scientific notation thresholds and trailing zero handling (PR #163, #165).

📚 Documentation and testing in v0.8.0

  • Refactor the testing files for Decimal128 (PR #132).
  • Refactor the benchmarking system to use TOML-based input files with configurable precision (PR #139, #159).
  • Update document links for the repository organization move to forfudan (PR #130).
  • Update documents and add the planning files for BigInt and BigDecimal optimization roadmaps (PR #157).

What's Changed

  • [decimal][rounding] Make RoundingMode type implicitly copyable by @forfudan in #125
  • [decimal] Implement quantize() function for BigDecimal by @forfudan in #126
  • [docs] Update the links in documents due to moving repo to an organization by @forfudan in #130
  • [integer][bigint] Unify initialization methods for unsigned integers by @forfudan in #131
  • [test] Refactor the testing files for Decimal128 by @forfudan in #132
  • [integer] Create basic methods for BigBinaryInt type by @forfudan in #133
  • [integer] Rename BigBinaryInt as BigInt2 by @forfudan in #134
  • [integer] Implement comparison and arithmetic routines for big binary int by @forfudan in #135
  • [bench] Refactor benchmarking system and use toml files as input by @forfudan in #139
  • [integer] Implement all necessary operations for big binary integer by @forfudan in #141
  • [integer] Implement Karatsuba algorithm for BigInt2 by @forfudan in #142
  • [integer] Rename BigInt as BigInt10 by @forfudan in #143
  • [integer][BInt2] Implement slice-based Burnikel-Ziegler algorithm for 2^32-based integer by @forfudan in #144
  • [integer][BInt2] Implement divide-and-conquer base conversion from BInt2 to String by @forfudan in #145
  • [integer][BigInt2] Improve the performance of from_string() and refactor the string parser by @forfudan in #146
  • [integer][BigInt2] Update conversion from 10-based integer to 2-based integer by @forfudan in #147
  • [integer][BigInt2] Optimize both the simple and D&C paths for from_string by @forfudan in #148
  • [integer][BigInt2] Optimize to_string() by @forfudan in #149
  • [integer][BigInt2] Add bitwise operations and true inplace operations by @forfudan in #150
  • [integer][BigInt2] Implement in-place bit-wise operations by @forfudan in #151
  • [integer][BigInt2] Implement GCD, extended GCD, and modular arithmetic by @forfudan in #152
  • [integer][BigInt2] Add methods for GCD, extended GCD, etc by @forfudan in #153
  • [integer] Rename BigInt2 as BigInt and bind the alias BInt to it by @forfudan in #154
  • [integer] Refactor sqrt() and significantly increase the speed by @...
Read more

DeciMojo v0.7.0

11 Feb 20:51
00a4793

Choose a tag to compare

20260212 (v0.7.0)

DeciMojo v0.7.0 updates the codebase to Mojo v0.26.1.

  • Replaces all alias declarations with comptime in all files. alias is deprecated.
  • Updates list and constant construction syntax throughout the codebase, e.g., replaced List[UInt32](...) with [UInt32(...), ...], used [word] instead of List[UInt32](word), etc. The old syntax is deprecated.
  • Updates list slicing syntax to use the new syntax. Now lst[1:] returns a Span instead of a List, so it needs to be converted to a list using the constructor List(...).
  • Updates some methods of the String type and the indexing and slicing syntax for String objects to match the latest Mojo syntax. The old syntax is deprecated.
  • Fixes the closure capture when using vectorize. The new syntax requires something like unified {read x, mut y} to capture variables x and y in the closure. The old syntax is deprecated.

What's Changed

  • [mojo] Update the codebase to Mojo v0.26.1 by @forfudan in #123
  • [release][docs] Update documents for release of v0.7.0 by @forfudan in #124

Full Changelog: v0.6.0...v0.7.0

DeciMojo v0.6.0

16 Dec 20:22
0fab1a2

Choose a tag to compare

20251216 (v0.6.0)

DeciMojo v0.6.0 updates the codebase to Mojo v0.25.7, adopting the new TestSuite type for improved test organization. All tests have been refactored to use the native Mojo testing framework instead of the deprecated pixi test command.

What's Changed

  • [mojo] Update the codebase to accommodate Mojo v0.25.6 by @forfudan in #120
  • [mojo] Update the codebase to Mojo v0.25.7 by @forfudan in #121
  • [release][docs] Update documents for version 0.6.0 by @forfudan in #122

Full Changelog: v0.5.0...v0.6.0

DeciMojo v0.5.0

06 Aug 20:13
02da4dc

Choose a tag to compare

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

DeciMojo v0.4.1

30 Jun 21:05
51c9832

Choose a tag to compare

01/07/2025 (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).

What's Changed

  • [integer][tests] Add operation overload between BigInt and Int + refactor some tests by @forfudan in #88
  • [integer][decimal] Allows implicit type conversion and type merging by @forfudan in #89
  • [integer][decimal][docs] Improve type conversions + optimize iadd for BigInt + Update documentation by @forfudan in #90

Full Changelog: v0.4.0...v0.4.1

DeciMojo v0.4.0

26 Jun 19:54
8ed3dab

Choose a tag to compare

25/06/2025 (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.

What's Changed

Full Changelog: v0.3.1...v0.4.0

DeciMojo v0.3.1

06 Jun 14:57
fd82601

Choose a tag to compare

06/06/2025 (v0.3.1)

DeciMojo v0.3.1 updates the codebase to Mojo 25.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.

What's Changed

  • [mojo] Update the code to accommodate with Mojo 25.3 by @forfudan in #85
  • [pixi] Change magic to pixi for environment and package management by @forfudan in #86

Full Changelog: v0.3.0...v0.3.1

DeciMojo v0.3.0

15 Apr 09:56
f2930f0

Choose a tag to compare

DeciMojo v0.3.0 for Mojo 25.2

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

  • Implement the BigDecimal type with unlimited precision arithmetic.
    • Implement basic arithmetic operations for BigDecimal: addition, subtraction, multiplication, division, and modulo.
    • Implement comparison operations for BigDecimal: less than, greater than, equal to, and not equal to.
    • Implement string representation and parsing for BigDecimal.
    • Implement mathematical operations for BigDecimal: sqrt, nroot, log, exp, and power functions.
    • Iimplement rounding functions.
  • Implement a simple TOML parser as package tomlmojo to refactor tests (PR #63).

🦋 Changed

  • Refine the constructors of BigUInt (PR #64).
  • Improve the method BigUInt.scale_up_by_power_of_10() (PR #72).

🛠️ Fixed

  • Fix a bug in BigUInt multiplication where the calcualtion of carry is mistakenly skipped if a word of x2 is zero (PR #70).

What's Changed

  • [toml] Implement a TOML parser as package tomlmojo and use it to re-factor tests by @forfudan in #63
  • [integer] Refine the constructors of BigUInt by @forfudan in #64
  • [decimal] Implement some IO methods for BigDecimal by @forfudan in #65
  • [decimal] Implement add for BigDecimal by @forfudan in #66
  • [decimal] Implement a subtraction function for BigDecimal by @forfudan in #67
  • [decimal] Add tests for subtract() of BigDecimal by @forfudan in #68
  • [decimal] Implement multiply() for BigDecimal type by @forfudan in #69
  • [decimal] Implement true_divide for BigDecimal type + fix a bug in BigUInt.multiply by @forfudan in #70
  • [decimal][integer] Implement comparison operators for BigDecimal + Improve BigUInt.scale_up_by_power_of_10() by @forfudan in #72
  • [decimal] Implement sqrt for BigDecimal by @forfudan in #73
  • [decimal] Implement exp() for BigDecimal by @forfudan in #74
  • [decimal] Optimize exp for BigDecimal by @forfudan in #75
  • [decimal] Implement ln for BigDecimal by @forfudan in #76
  • [decimal] Implement power function for BigDecimal by @forfudan in #77
  • [docs] Update descriptions and examples by @forfudan in #78
  • [docs] Update descriptions and examples by @forfudan in #79
  • [decimal] Implement root() for BigDecimal by @forfudan in #80
  • [decimal][tests] Add tests for root() and power() of BigDecimal by @forfudan in #81
  • [integer] Remove multiply_toom_cook_3 for BigUInt by @forfudan in #82
  • [decimal] Implement round() for BigDecimal by @forfudan in #83
  • [docs] Update documents for release by @forfudan in #84

Full Changelog: v0.2.0...v0.3.0

DeciMojo v0.2.0

27 Mar 17:24
fba2fa8

Choose a tag to compare

DeciMojo v0.2.0 for Mojo 25.2

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.

DeciMojo division performance compared with Python's decimal module across versions:

Division Operation v0.1.0 vs Python v0.2.0 vs Python Improvement
Integer division (no remainder) 0.15× (slower) 485.88× faster 3239×
Simple decimal division 0.13× (slower) 185.77× faster 1429×
Division with repeating decimal 0.04× (slower) 12.46× faster 311×
Division by one 0.15× (slower) 738.60× faster 4924×
Division of zero 1820.50× faster 1866.50× faster 1.03×
Division with negative numbers 0.11× (slower) 159.32× faster 1448×
Division by very small number 0.21× (slower) 452.75× faster 2156×
High precision division 0.005× (slower) 15.19× faster 3038×
Division resulting in power of 10 0.21× (slower) 619.00× faster 2948×
Division of very large numbers 0.06× (slower) 582.86× faster 9714×

Note: Benchmarks performed on Darwin 24.3.0, arm processor with Python 3.12.9. The dramatic performance improvements in v0.2.0 come from completely rewriting the division algorithm using Mojo 25.2's UInt128 implementation. While v0.1.0 was generally slower than Python for division operations (except for division of zero), v0.2.0 achieves speedups of 12-1866× depending on the specific scenario.

⭐️ New

  • Add comprehensive 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.

🦋 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.

❌ Removed

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

🛠️ 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.

📚 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.

What's Changed

  • [decimal][bench] change return type of coefficient() to UInt128 + add benches by @forfudan in #15
  • [decimal] Optimize add() function and remove string-based addition and subtraction by @forfudan in #16
  • [repo] Move decimojo folder into src folder by @forfudan in #17
  • [decimal] Add bit_cast() and fix truncate_to_max() by @forfudan in #18
  • [decimojo] Use bitcast() for coefficient() by @forfudan in #19
  • [decimal] Optimize multiply() with UInt128 and UInt256 by @forfudan in #20
  • [decimal] Optimize divide() and replace string-based approach with int-based approach by @forfudan in #21
  • [decimal] Optimize sqrt() function by improving initial guess by @forfudan in #22
  • [decimojo][fix] Enhance round() function and improve the performance + fix sqrt() by @forfudan in #23
  • [decimal] Re-write Decimal constructor from floating-point value from_float() by @forfudan in #24
  • [decimal] Remove str._float_to_decimal_str() + Add bench for from_string by @forfudan in #25
  • [decimal] Re-write from_string() constructor and improve the performance by @forfudan in #26
  • [decimal] Update comparison functions + code reorganization by @forfudan in #27
  • [decimal] Add cache for powers of 10 by @forfudan in #28
  • [decimal] simplifying initialization of Decimal and add from_uint128() by @forfudan in #29
  • [decimal] Implement factorial() and exp() function by @forfudan in #30
  • [decimal] Optimize number_of_digit + improve the performance of multiply and exp by @forfudan in #31
  • [test] Add more tests for multiply() by @forfudan in #32
  • [decimal] Update Decimal constructors by @forfudan in #33
  • [test] Add separate testing files for __int__, __float__, __str__ by @forfudan in #34
  • [docs] Change DeciMojo in URLs to lowercase by @forfudan in #35
  • [decimal] Implement ln() function that gets natural logarithm by @forfudan in #36
  • [decimal] Enhance power() function to accept a Decimal exponent by @forfudan in #37
  • [decimal] Updates to the Decimal type by @forfudan in #38
  • [fix] Fix bug in multiply() due to implicit type conversion by @forfudan in #39
  • [decimal] Implement root() function to calculate the n-th root of a Decimal value by @forfudan in #40
  • [decimal] Refine Decimal struct + improve docstrings by @forfudan in #41
  • [decimal] Make Decimal type trivial + Add to_str_scientific() method by @forfudan in #42
  • [decimal] Implement the log() and the log10() functions by @forfudan in #43
  • [decimal] Implement the quantize() function by @forfudan in #44
  • [decimal] Implement floor_divide and modulo functions (// and %) by @forfudan in #45
  • [repo][docs] Reorganize the repo + update the readme file by @forfudan in #46
  • [docs] Update the readme file by @forfudan in #47
  • [bigint] Implement BigInt type and basic arithmetic operations by @forfudan in #48
  • [bigint] Add to_int and improve from_int by @forfudan in #49
  • [bigint] Optimize parsing of numeric strings by @forfudan in #50
  • [bigint] Implement multiply for BigInt by @forfudan in #51
  • [decimal] Rename floor_divide to truncate_divide to avoid ambiguity by @forfudan in #52
  • [bigint] Implement truncate_divide and truncate_modulo for BigInt by @forfudan in #53
  • [integer] Implement BigUInt, basic methods and arithmetic functions by @forfudan in #54...
Read more