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
Copy file name to clipboardExpand all lines: recipes/decimojo/README.md
+37-47Lines changed: 37 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,36 +1,45 @@
1
-
# DeciMojo
1
+
# DeciMojo<!-- omit in toc -->
2
2
3
3

4
4
5
-
A comprehensive decimal and integer mathematics library for [Mojo](https://www.modular.com/mojo).
5
+
An arbitrary-precision decimal and integer mathematics library for [Mojo](https://www.modular.com/mojo).
6
6
7
-
**[中文·漢字»](https://zhuyuhao.com/decimojo/docs/readme_zht.html)** | **[Repository on GitHub»](https://github.com/forfudan/decimojo)**
7
+
**[中文·漢字»](https://zhuyuhao.com/decimojo/docs/readme_zht.html)** | **[Repository on GitHub»](https://github.com/forfudan/decimojo)** | **[Changelog](https://zhuyuhao.com/decimojo/docs/changelog.html)**
8
8
9
9
## Overview
10
10
11
-
DeciMojo provides a comprehensive decimal and integer mathematics library for Mojo, delivering exact calculations for financial modeling, scientific computing, and applications where floating-point approximation errors are unacceptable. Beyond basic arithmetic, the library includes advanced mathematical functions with guaranteed precision.
11
+
DeciMojo provides an arbitrary-precision decimal and integer mathematics library for Mojo, delivering exact calculations for financial modeling, scientific computing, and applications where floating-point approximation errors are unacceptable. Beyond basic arithmetic, the library includes advanced mathematical functions with guaranteed precision.
12
12
13
13
The core types are:
14
14
15
-
- 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.
15
+
- 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, etc.
16
+
- An arbitrary-precision decimal implementation `BigDecimal` allowing for calculations with unlimited digits and decimal places[^arbitrary].
16
17
- 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.
17
18
18
-
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.
19
+
This repository includes [TOMLMojo](https://github.com/forfudan/decimojo/tree/main/src/tomlmojo), a lightweight TOML parser in pure Mojo. It parses configuration files and test data, supporting basic types, arrays, and nested tables. While created for DeciMojo's testing framework, it offers general-purpose structured data parsing with a clean, simple API.
20
+
21
+
| type | alias | information | internal representation |
DeciMojo is available in the [modular-community](https://repo.prefix.dev/modular-community) package repository. You can install it using any of these methods:
23
31
24
32
From the `magic` CLI, simply run ```magic add decimojo```. This fetches the latest version and makes it immediately available for import.
25
33
26
-
For projects with a `mojoproject.toml`file, add the dependency ```decimojo = ">=0.2.0"```. Then run `magic install` to download and install the package.
34
+
For projects with a `mojoproject.toml`file, add the dependency ```decimojo = ">=0.3.0"```. Then run `magic install` to download and install the package.
27
35
28
36
For the latest development version, clone the [GitHub repository](https://github.com/forfudan/decimojo) and build the package locally.
29
37
30
38
|`decimojo`|`mojo`|
31
39
| ---------- | ------ |
32
40
| v0.1.0 | >=25.1 |
33
41
| v0.2.0 | >=25.2 |
42
+
| v0.3.0 | >=25.2 |
34
43
35
44
## Quick start
36
45
@@ -99,6 +108,24 @@ fn main() raises:
99
108
100
109
[Click here for 8 key examples](https://zhuyuhao.com/decimojo/docs/examples) highlighting the most important features of the `Decimal` type.
101
110
111
+
Here are some examples showcasing the arbitrary-precision feature of the `BigDecimal` type.
Here is a comprehensive quick-start guide showcasing each major function of the `BigInt` type.
103
130
104
131
```mojo
@@ -160,47 +187,10 @@ The name ultimately emphasizes our mission: bringing precise, reliable decimal c
160
187
161
188
## Status
162
189
163
-
Rome wasn't built in a day. DeciMojo is currently under active development. For the 128-bit `Decimal` type, it has successfully progressed through the **"make it work"** phase and is now well into the **"make it right"** phase with many optimizations already in place. Bug reports and feature requests are welcome! If you encounter issues, please [file them here](https://github.com/forfudan/decimojo/issues).
164
-
165
-
### Make it Work ✅ (COMPLETED)
166
-
167
-
- Core decimal implementation with a robust 128-bit representation (96-bit coefficient + 32-bit flags)
- Proper implementation of traits (Absable, Comparable, Floatable, Roundable, etc).
181
-
-**BigInt and BigUInt** implementations with complete arithmetic operations, proper division semantics (floor and truncate), and support for arbitrary-precision calculations.
182
-
183
-
### Make it Fast ⚡ (SIGNIFICANT PROGRESS)
184
-
185
-
DeciMojo delivers exceptional performance compared to Python's `decimal` module while maintaining precise calculations. This performance difference stems from fundamental design choices:
186
-
187
-
-**DeciMojo**: Uses a fixed 128-bit representation (96-bit coefficient + 32-bit flags) with a maximum of 28 decimal places, optimized for modern hardware and Mojo's performance capabilities.
188
-
-**Python decimal**: Implements arbitrary precision that can represent numbers with unlimited significant digits but requires dynamic memory allocation and more complex algorithms.
189
-
190
-
This architectural difference explains our benchmarking results:
- Only specific edge cases (like computing 10^(1/100)) occasionally perform better in Python due to its arbitrary precision algorithms.
190
+
Rome wasn't built in a day. DeciMojo is currently under active development. It has successfully progressed through the **"make it work"** phase and is now well into the **"make it right"** phase with many optimizations already in place. Bug reports and feature requests are welcome! If you encounter issues, please [file them here](https://github.com/forfudan/decimojo/issues).
196
191
197
192
Regular benchmarks against Python's `decimal` module are available in the `bench/` folder, documenting both the performance advantages and the few specific operations where different approaches are needed.
198
193
199
-
### Future Extensions 🚀 (PLANNED)
200
-
201
-
-**BigDecimal**: 🔄 **IN PROGRESS** - Arbitrary-precision decimal type with configurable precision[^arbitrary].
202
-
-**BigComplex**: 📝 **PLANNED** - Arbitrary-precision complex number type built on BigDecimal.
203
-
204
194
## Tests and benches
205
195
206
196
After cloning the repo onto your local disk, you can:
@@ -216,9 +206,9 @@ If you find DeciMojo useful for your research, consider listing it in your citat
216
206
@software{Zhu.2025,
217
207
author = {Zhu, Yuhao},
218
208
year = {2025},
219
-
title = {A comprehensive decimal and integer mathematics library for Mojo},
209
+
title = {An arbitrary-precision decimal and integer mathematics library for Mojo},
0 commit comments