Decimo v0.8.0
20260225 (v0.8.0)
Library renamed from
decimojotodecimo. 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):
- Implement the
BigInt(BInt) type using a base-2^32 internal representation with little-endianUInt32words. This is a completely new implementation optimized for binary computations while supporting arbitrary precision (PR #133, #134, #135, #141). - 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). - Implement the slice-based Burnikel-Ziegler division algorithm for
BigInt, providing sub-quadratic division performance for the base-2^32 representation (PR #144). - Implement divide-and-conquer base conversion for
BigInt.to_string(), significantly improving string conversion speed for large integers (PR #145). - Implement bitwise operations (
__and__,__or__,__xor__,__lshift__,__rshift__,__invert__) and true in-place bitwise operations forBigInt(PR #150, #151). - Implement
gcd(),extended_gcd(),mod_inverse(), andmod_pow()forBigInt, providing number-theoretic functions (PR #152, #153). - Implement an optimized
sqrt()forBigIntusing Newton's method with a good initial approximation, delivering 1.39× average speedup over Python (PR #155).
BigDecimal:
- Implement the
quantize()function forBigDecimalto format decimal numbers to a specified number of decimal places, similar to Python'sDecimal.quantize()(PR #126). - Implement true in-place arithmetic functions (
__iadd__,__isub__,__imul__) forBigDecimalto reduce memory allocations during repeated operations (PR #162). - Implement methods to initialize
BigIntandBigDecimalfrom Python objects, enabling seamless interoperability with Python'sintanddecimal.Decimal(PR #129).
Core:
- Add
ROUND_CEILINGandROUND_FLOORrounding modes toRoundingMode, bringing the total to six modes (PR #164).
TOMLMojo:
- 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:
- Rename the previous base-10^9
BigInttoBigInt10. The aliasBIntnow refers to the new base-2^32BigInttype (PR #143, #154). - Optimize
from_string()forBigIntwith an improved string parser and divide-and-conquer approach for fast base conversion (PR #146, #147, #148). - Optimize
to_string()forBigIntwith divide-and-conquer base conversion, achieving 6× average speedup over Python (PR #149).
BigDecimal:
- Re-implement
sqrt()forBigDecimalusing the reciprocal square root method combined with Newton's method, delivering faster convergence and better accuracy for high-precision calculations (PR #163). - Optimize
ln()andexp()forBigDecimalwith mathematical constant caching viaMathCacheand improved handling of one-word dividends (PR #160). - Apply aggressive range reduction for
exp()to achieve faster convergence at high precision (PR #167). - Implement direct Newton method for general
root()calculation, replacing the previous iterative approach (PR #161). - Add rational root decomposition to
root()and an atanh-based approach toln()for improved accuracy and convergence (PR #168). - Optimize
true_divide_general()to correctly account for existing word surplus in the dividend (PR #158). - Optimize division with truncation and align
to_string()output with CPython'sdecimalmodule formatting for scientific notation and trailing zeros (PR #165).
BigUInt:
- Implement the Toom-Cook 3-way multiplication algorithm for
BigUInt, improving performance for large number multiplications (PR #166). - Unify and refine initialization methods for
BigUIntwith consistent constructors and improved validation (PR #127, #128, #131).
Core:
- Improve naming consistency between types, ensuring uniform method names across
BigInt,BigDecimal, andDecimal128(PR #164). - Make
RoundingModetype implicitly copyable for easier usage in function signatures (PR #125).
🛠️ Fixed in v0.8.0
- Fix string formatting for
BigDecimalto match Python'sdecimalmodule 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
RoundingModetype implicitly copyable by @forfudan in #125 - [decimal] Implement
quantize()function forBigDecimalby @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
Decimal128by @forfudan in #132 - [integer] Create basic methods for BigBinaryInt type by @forfudan in #133
- [integer] Rename
BigBinaryIntasBigInt2by @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
BigInt2by @forfudan in #142 - [integer] Rename
BigIntasBigInt10by @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_stringby @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
BigInt2asBigIntand bind the aliasBIntto it by @forfudan in #154 - [integer] Refactor
sqrt()and significantly increase the speed by @forfudan in #155 - [integer][docs] Update several documents and add the planning file for BigDecimal optimization by @forfudan in #157
- [decimal] Update
true_divide_general()to account for existing word surplus in dividend by @forfudan in #158 - [bench] Add precision in toml files for benches by @forfudan in #159
- [decimal] Improve
lnandexpwith caching and new function handling one-word dividend by @forfudan in #160 - [decimal] Use direct Newton method for general root calculation by @forfudan in #161
- [decimal] Implement true in-place functions for
BigDecimaltype by @forfudan in #162 - [decimal] Refactor
sqrt()+ fix string formatting to match Python's decimal rule by @forfudan in #163 - [core] Add more rounding modes + improve naming consistency between types by @forfudan in #164
- [decimal][core][test] Division truncation optimization +
to_string()CPython alignment + test refactor by @forfudan in #165 - [biguint] Implement Toom-Cook 3-way algorithm for BigUInt multiplication by @forfudan in #166
- [decimal] Apply aggressive range reduction for
expby @forfudan in #167 - [decimal] Add rational root decompostion to
root()and add atanh approach toln()by @forfudan in #168
Full Changelog: v0.7.0...v0.8.0