Repository navigation
DeciMojo v0.2.0
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
BigIntandBigUIntimplementation with unlimited precision integer arithmetic. - Implement full arithmetic operations for
BigIntandBigUInt: 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
BigIntwith proper handling of negative values. - Implement efficient string representation and parsing for
BigIntandBigUInt. - 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
Decimaltype usingUInt128introduced in Mojo 25.2. This significantly improves the performance ofDecimaloperations. - Improve memory management system to reduce allocations during calculations.
- Reorganize codebase with modular structure (decimal, arithmetics, comparison, exponential).
- Enhance
Decimalcomparison operators for better handling of edge cases. - Update internal representation of
Decimalfor 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
BigIntandBigUIntwith over 200 test cases covering all operations and edge cases. - Create detailed API documentation for both
DecimalandBigInt. - 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
decimojofolder intosrcfolder by @forfudan in #17 - [decimal] Add
bit_cast()and fixtruncate_to_max()by @forfudan in #18 - [decimojo] Use
bitcast()forcoefficient()by @forfudan in #19 - [decimal] Optimize
multiply()withUInt128andUInt256by @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 + fixsqrt()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
Decimaland addfrom_uint128()by @forfudan in #29 - [decimal] Implement
factorial()andexp()function by @forfudan in #30 - [decimal] Optimize
number_of_digit+ improve the performance ofmultiplyandexpby @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
Decimaltype 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
Decimalstruct + improve docstrings by @forfudan in #41 - [decimal] Make
Decimaltype trivial + Addto_str_scientific()method by @forfudan in #42 - [decimal] Implement the
log()and thelog10()functions by @forfudan in #43 - [decimal] Implement the
quantize()function by @forfudan in #44 - [decimal] Implement
floor_divideandmodulofunctions (// 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
BigInttype and basic arithmetic operations by @forfudan in #48 - [bigint] Add
to_intand improvefrom_intby @forfudan in #49 - [bigint] Optimize parsing of numeric strings by @forfudan in #50
- [bigint] Implement
multiplyforBigIntby @forfudan in #51 - [decimal] Rename
floor_dividetotruncate_divideto avoid ambiguity by @forfudan in #52 - [bigint] Implement
truncate_divideandtruncate_moduloforBigIntby @forfudan in #53 - [integer] Implement
BigUInt, basic methods and arithmetic functions by @forfudan in #54 - [integer] Refine the
BigUIntdivision operation by @forfudan in #55 - [integer] Optimize
BigUInttype and its arithmetic operations by @forfudan in #56 - [integer] Implement several dunder methods for
BigUIntby @forfudan in #57 - [max] Update max version to 25.2 by @forfudan in #58
- [integer] Update functions and methods for
BigUIntby @forfudan in #59 - [integer] Enhance the comparison operations of
BigIntby @forfudan in #60 - [integer] Re-write arithmetic functions of
BigIntby usingBigUInt's methods by @forfudan in #61 - [doc] Update changelog and readme files by @forfudan in #62
Full Changelog: v0.1.0...v0.2.0