Skip to content

Commit fba2fa8

Browse files
authored
[doc] Update changelog and readme files (#62)
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.
1 parent df8e221 commit fba2fa8

File tree

6 files changed

+254
-226
lines changed

6 files changed

+254
-226
lines changed

README.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A comprehensive decimal and integer mathematics library for [Mojo](https://www.modular.com/mojo).
44

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)**
66

77
## Overview
88

@@ -11,7 +11,7 @@ DeciMojo provides a comprehensive decimal and integer mathematics library for Mo
1111
The core types are:
1212

1313
- 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.
1515

1616
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.
1717

@@ -21,7 +21,7 @@ DeciMojo is available in the [modular-community](https://repo.prefix.dev/modular
2121

2222
From the `magic` CLI, simply run ```magic add decimojo```. This fetches the latest version and makes it immediately available for import.
2323

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

2626
For the latest development version, clone the [GitHub repository](https://github.com/forfudan/decimojo) and build the package locally.
2727

@@ -95,36 +95,49 @@ fn main() raises:
9595
print(Decimal("12.34").to_str_scientific()) # Scientific notation: 1.234E+1
9696
```
9797

98-
[Click here for 8 key examples](./docs/examples.md) highlighting the most important features of the `Decimal` type.
98+
[Click here for 8 key examples](https://zhuyuhao.com/decimojo/docs/examples) highlighting the most important features of the `Decimal` type.
9999

100-
### BigInt Quick Start
100+
Here is a comprehensive quick-start guide showcasing each major function of the `BigInt` type.
101101

102102
```mojo
103-
from decimojo.bigint import BigInt
103+
from decimojo import BigInt, BInt
104+
# BInt is an alias for BigInt
104105
105106
fn main() raises:
106107
# === Construction ===
107108
var a = BigInt("12345678901234567890") # From string
108-
var b = BigInt(12345) # From integer
109+
var b = BInt(12345) # From integer
109110
110111
# === Basic Arithmetic ===
111112
print(a + b) # Addition: 12345678901234580235
112113
print(a - b) # Subtraction: 12345678901234555545
113114
print(a * b) # Multiplication: 152415787814108380241050
114-
print(a.truncate_divide(b)) # Division: 999650944609516
115+
116+
# === Division Operations ===
117+
print(a // b) # Floor division: 999650944609516
118+
print(a.truncate_divide(b)) # Truncate division: 999650944609516
119+
print(a % b) # Modulo: 9615
120+
121+
# === Power Operation ===
122+
print(BInt(2).power(10)) # Power: 1024
123+
print(BInt(2) ** 10) # Power (using ** operator): 1024
115124
116125
# === Comparison ===
117126
print(a > b) # Greater than: True
118-
print(a == BigInt("12345678901234567890")) # Equality: True
127+
print(a == BInt("12345678901234567890")) # Equality: True
119128
print(a.is_zero()) # Check for zero: False
120129
121130
# === Type Conversions ===
122131
print(a.to_str()) # To string: "12345678901234567890"
123132
124133
# === Sign Handling ===
125134
print(-a) # Negation: -12345678901234567890
126-
print(abs(BigInt("-12345678901234567890"))) # Absolute value: 12345678901234567890
135+
print(abs(BInt("-12345678901234567890"))) # Absolute value: 12345678901234567890
127136
print(a.is_negative()) # Check if negative: False
137+
138+
# === Extremely large numbers ===
139+
# 3600 digits // 1800 digits
140+
print(BInt("123456789" * 400) // BInt("987654321" * 200))
128141
```
129142

130143
## Objective
@@ -139,7 +152,7 @@ This project draws inspiration from several established decimal implementations
139152

140153
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.
141154

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

144157
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.
145158

@@ -163,6 +176,7 @@ Rome wasn't built in a day. DeciMojo is currently under active development. For
163176
- Financial calculations with banker's rounding (ROUND_HALF_EVEN).
164177
- High-precision advanced mathematical functions (sqrt, root, ln, exp, log10, power).
165178
- 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.
166180

167181
### Make it Fast ⚡ (SIGNIFICANT PROGRESS)
168182

@@ -200,9 +214,9 @@ If you find DeciMojo useful for your research, consider listing it in your citat
200214
@software{Zhu.2025,
201215
author = {Zhu, Yuhao},
202216
year = {2025},
203-
title = {DeciMojo: A comprehensive decimal mathematics library for Mojo},
217+
title = {A comprehensive decimal and integer mathematics library for Mojo},
204218
url = {https://github.com/forfudan/decimojo},
205-
version = {0.1.0},
219+
version = {0.2.0},
206220
note = {Computer Software}
207221
}
208222
```
@@ -212,5 +226,5 @@ If you find DeciMojo useful for your research, consider listing it in your citat
212226
This repository and its contributions are licensed under the Apache License v2.0.
213227

214228
[^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.
216230
[^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.

docs/changelog.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# DeciMojo released changelog
2+
3+
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 |
12+
| --------------------------------- | ---------------- | ---------------- | ----------- |
13+
| Integer division (no remainder) | 0.15× (slower) | 485.88× faster | 3239× |
14+
| Simple decimal division | 0.13× (slower) | 185.77× faster | 1429× |
15+
| Division with repeating decimal | 0.04× (slower) | 12.46× faster | 311× |
16+
| Division by one | 0.15× (slower) | 738.60× faster | 4924× |
17+
| Division of zero | 1820.50× faster | 1866.50× faster | 1.03× |
18+
| Division with negative numbers | 0.11× (slower) | 159.32× faster | 1448× |
19+
| Division by very small number | 0.21× (slower) | 452.75× faster | 2156× |
20+
| High precision division | 0.005× (slower) | 15.19× faster | 3038× |
21+
| 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.
44+
45+
### ❌ Removed
46+
47+
- Remove deprecated legacy string formatting methods.
48+
- Remove redundant conversion functions that were replaced with a more unified API.
49+
50+
### 🛠️ Fixed
51+
52+
- Fix edge cases in division operations with zero and one.
53+
- Correct sign handling in mixed-sign operations for both `Decimal`.
54+
- Fix precision loss in repeated addition/subtraction operations.
55+
- Correct rounding behavior in edge cases for financial calculations.
56+
- Address inconsistencies between operator methods and named functions.
57+
58+
### 📚 Documentation and testing
59+
60+
- Add comprehensive test suite for `BigInt` and `BigUInt` with over 200 test cases covering all operations and edge cases.
61+
- Create detailed API documentation for both `Decimal` and `BigInt`.
62+
- Add performance comparison benchmarks between DeciMojo and Python's decimal/int implementation.
63+
- Update multi-language documentation to include all new functionality (English and Chinese).
64+
- Include clear explanations of division semantics and other potentially confusing numerical concepts.

0 commit comments

Comments
 (0)