You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request includes several updates and improvements to the
`README.md` and other documentation files for the DeciMojo library, as
well as the addition of a new changelog. The most important changes
include the introduction of `BigUInt`, updates to the installation
instructions, and enhancements to the `BigInt` and `Decimal`
functionalities.
### Enhancements to `BigInt` and `BigUInt`:
* Added a new `BigUInt` type and extended the `BigInt` type to support
unlimited precision arithmetic, comprehensive arithmetic operations, and
efficient handling of extremely large integers.
[[1]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L14-R14)
[[2]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R178)
* Enhanced `BigInt` with floor division, truncate division, modulo, and
power operations.
[[1]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L114-R122)
[[2]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R136-R139)
### Updates to Installation Instructions:
* Updated the installation instructions to reflect the new version
`0.2.0` in the `mojoproject.toml` file.
### Documentation Improvements:
* Updated the `README.md` to reflect changes in the `BigInt` and
`Decimal` types, including new mathematical functions and division
operations.
[[1]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L103-R103)
[[2]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L215-R228)
* Added a new `docs/changelog.md` file to document the changes and
improvements in version `0.2.0`, including performance benchmarks and
detailed descriptions of new features and bug fixes.
### Additional Changes:
* Made minor updates to the Chinese documentation (`docs/readme_zht.md`)
to include the new `BigUInt` type and updated installation instructions.
Copy file name to clipboardExpand all lines: README.md
+28-14Lines changed: 28 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
A comprehensive decimal and integer mathematics library for [Mojo](https://www.modular.com/mojo).
4
4
5
-
**[中文·漢字»](./docs/readme_zht.md)** | **[Repository on GitHub»](https://github.com/forfudan/decimojo)**
5
+
**[中文·漢字»](https://zhuyuhao.com/decimojo/docs/readme_zht.html)** | **[Repository on GitHub»](https://github.com/forfudan/decimojo)**
6
6
7
7
## Overview
8
8
@@ -11,7 +11,7 @@ DeciMojo provides a comprehensive decimal and integer mathematics library for Mo
11
11
The core types are:
12
12
13
13
- A 128-bit fixed-point decimal implementation (`Decimal`) supporting up to 29 significant digits with a maximum of 28 decimal places[^fixed]. It features a complete set of mathematical functions including logarithms, exponentiation, roots, and trigonometric operations.
14
-
- A base-10 arbitrary-precision integer type (`BigInt`)[^integer]supporting unlimited digits. It features base-10^9 internal representation and basic arithmetic operations.
14
+
- A base-10 arbitrary-precision signed integer type (`BigInt`) and a base-10 arbitrary-precision unsigned integer type (`BigUInt`) supporting unlimited digits[^integer]. It features comprehensive arithmetic operations, comparison functions, and supports extremely large integer calculations efficiently.
15
15
16
16
The library is expanding to include `BigDecimal` types that support arbitrary precision[^arbitrary], allowing for calculations with unlimited digits and decimal places. These extensions are currently under active development.
17
17
@@ -21,7 +21,7 @@ DeciMojo is available in the [modular-community](https://repo.prefix.dev/modular
21
21
22
22
From the `magic` CLI, simply run ```magic add decimojo```. This fetches the latest version and makes it immediately available for import.
23
23
24
-
For projects with a `mojoproject.toml`file, add the dependency ```decimojo = ">=0.1.0"```. Then run `magic install` to download and install the package.
24
+
For projects with a `mojoproject.toml`file, add the dependency ```decimojo = ">=0.2.0"```. Then run `magic install` to download and install the package.
25
25
26
26
For the latest development version, clone the [GitHub repository](https://github.com/forfudan/decimojo) and build the package locally.
@@ -139,7 +152,7 @@ This project draws inspiration from several established decimal implementations
139
152
140
153
DeciMojo combines "Deci" and "Mojo" - reflecting its purpose and implementation language. "Deci" (from Latin "decimus" meaning "tenth") highlights our focus on the decimal numeral system that humans naturally use for counting and calculations.
141
154
142
-
Although the name emphasizes decimals with fractional parts, DeciMojo embraces the full spectrum of decimal mathematics. Our `BigInt` type, while handling only integers, is designed specifically for the decimal numeral system with its base-10^9 internal representation. This approach offers optimal performance while maintaining human-readable decimal semantics, contrasting with binary-focused libraries. Furthermore, `BigInt` serves as the foundation for our `BigDecimal` implementation, enabling arbitrary-precision calculations across both integer and fractional domains.
155
+
Although the name emphasizes decimals with fractional parts, DeciMojo embraces the full spectrum of decimal mathematics. Our `BigInt` type, while handling only integers, is designed specifically for the decimal numeral system with its base-10 internal representation. This approach offers optimal performance while maintaining human-readable decimal semantics, contrasting with binary-focused libraries. Furthermore, `BigInt` serves as the foundation for our `BigDecimal` implementation, enabling arbitrary-precision calculations across both integer and fractional domains.
143
156
144
157
The name ultimately emphasizes our mission: bringing precise, reliable decimal calculations to the Mojo ecosystem, addressing the fundamental need for exact arithmetic that floating-point representations cannot provide.
145
158
@@ -163,6 +176,7 @@ Rome wasn't built in a day. DeciMojo is currently under active development. For
163
176
- Financial calculations with banker's rounding (ROUND_HALF_EVEN).
- Proper implementation of traits (Absable, Comparable, Floatable, Roundable, etc).
179
+
-**BigInt and BigUInt** implementations with complete arithmetic operations, proper division semantics (floor and truncate), and support for arbitrary-precision calculations.
166
180
167
181
### Make it Fast ⚡ (SIGNIFICANT PROGRESS)
168
182
@@ -200,9 +214,9 @@ If you find DeciMojo useful for your research, consider listing it in your citat
200
214
@software{Zhu.2025,
201
215
author = {Zhu, Yuhao},
202
216
year = {2025},
203
-
title = {DeciMojo: A comprehensive decimal mathematics library for Mojo},
217
+
title = {A comprehensive decimal and integer mathematics library for Mojo},
204
218
url = {https://github.com/forfudan/decimojo},
205
-
version = {0.1.0},
219
+
version = {0.2.0},
206
220
note = {Computer Software}
207
221
}
208
222
```
@@ -212,5 +226,5 @@ If you find DeciMojo useful for your research, consider listing it in your citat
212
226
This repository and its contributions are licensed under the Apache License v2.0.
213
227
214
228
[^fixed]: The `Decimal` type can represent values with up to 29 significant digits and a maximum of 28 digits after the decimal point. When a value exceeds the maximum representable value (`2^96 - 1`), DeciMojo either raises an error or rounds the value to fit within these constraints. For example, the significant digits of `8.8888888888888888888888888888` (29 eights total with 28 after the decimal point) exceeds the maximum representable value (`2^96 - 1`) and is automatically rounded to `8.888888888888888888888888889` (28 eights total with 27 after the decimal point). DeciMojo's `Decimal` type is similar to `System.Decimal` (C#/.NET), `rust_decimal` in Rust, `DECIMAL/NUMERIC` in SQL Server, etc.
215
-
[^integer]: The BigInt implementation uses a base-10^9 representation for efficient storage and calculations, supporting operations on integers with unlimited precision. It serves both as a standalone arbitrary-precision integer type and as the foundation for our upcoming BigDecimal implementation.
229
+
[^integer]: The BigInt implementation uses a base-10 representation for users (maintaining decimal semantics), while internally using an optimized base-10^9 storage system for efficient calculations. This approach balances human-readable decimal operations with high-performance computing. It provides both floor division (round toward negative infinity) and truncate division (round toward zero) semantics, enabling precise handling of division operations with correct mathematical behavior regardless of operand signs.
216
230
[^arbitrary]: Built on top of our completed BigInt implementation, BigDecimal will support arbitrary precision for both the integer and fractional parts, similar to `decimal` and `mpmath` in Python, `java.math.BigDecimal` in Java, etc.
This is a list of RELEASED changes for the DeciMojo Package.
4
+
5
+
## 01/04/2025 (v0.2.0)
6
+
7
+
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.
8
+
9
+
DeciMojo division performance compared with Python's `decimal` module across versions:
10
+
11
+
| Division Operation | v0.1.0 vs Python | v0.2.0 vs Python | Improvement |
| Division resulting in power of 10 | 0.21× (slower) | 619.00× faster | 2948× |
22
+
| Division of very large numbers | 0.06× (slower) | 582.86× faster | 9714× |
23
+
24
+
_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._
25
+
26
+
### ⭐️ New
27
+
28
+
- Add comprehensive `BigInt` and `BigUInt` implementation with unlimited precision integer arithmetic.
29
+
- Implement full arithmetic operations for `BigInt` and `BigUInt`: addition, subtraction, multiplication, division, modulo and power operations.
30
+
- Support both floor division (round toward negative infinity) and truncate division (round toward zero) semantics for mathematical correctness.
31
+
- Add complete comparison operations for `BigInt` with proper handling of negative values.
32
+
- Implement efficient string representation and parsing for `BigInt` and `BigUInt`.
33
+
- Add advanced mathematical operations for `Decimal`: square root and n-th root.
34
+
- Add logarithm functions for `Decimal`: natural logarithm, base-10 logarithm, and logarithm with arbitrary base.
35
+
- Add exponential function and power function with arbitrary exponents for `Decimal`.
36
+
37
+
### 🦋 Changed
38
+
39
+
- 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.
40
+
- Improve memory management system to reduce allocations during calculations.
41
+
- Reorganize codebase with modular structure (decimal, arithmetics, comparison, exponential).
42
+
- Enhance `Decimal` comparison operators for better handling of edge cases.
43
+
- Update internal representation of `Decimal` for better precision handling.
0 commit comments