Skip to content

Commit 02da4dc

Browse files
authored
[release][docs] Update documents for the release of version 0.5.0 (#118)
This pull request updates documentation and examples to reflect the new v0.5.0 release of DeciMojo, improves clarity for both English and Chinese readers, and adds comprehensive usage examples for all major types. The changes ensure consistency with the latest features, update installation and compatibility instructions, and provide quick start guides for `BigInt` and `Decimal128`. **Documentation and Usage Examples:** - Added detailed example files: `docs/examples_on_bigint.mojo` and `docs/examples_on_decimal128.mojo` to demonstrate the construction, arithmetic, conversions, and advanced features of `BigInt` and `Decimal128`. - Expanded and clarified the Chinese README (`docs/readme_zht.md`) with a full table of contents, improved type descriptions, installation instructions, and comprehensive quick start guides for `BigInt`, `BigDecimal`, and `Decimal128`. - Updated the English `README.md` to clarify installation steps, version compatibility, and usage of type aliases, and to improve example explanations. **Release and Versioning Updates:** - Updated the changelog (`docs/changelog.md`) to reflect the new release date and summarize the new features and improvements in v0.5.0, including enhanced math functions, performance optimizations, and compatibility with Mojo v25.5. - Updated package version requirements in `pixi.toml` and documentation tables to require Mojo v25.5 for DeciMojo v0.5.0, ensuring users install compatible versions. **Citation and Metadata:** - Updated citation and software metadata in the Chinese README to match the new version and scope of the library. **Other Improvements:** - Improved and clarified footnotes and technical explanations in the Chinese README, including details about internal representations and division semantics. These changes ensure that documentation, examples, and metadata are up-to-date and provide clear guidance for both English and Chinese users.
1 parent 27df8c9 commit 02da4dc

File tree

10 files changed

+388
-55
lines changed

10 files changed

+388
-55
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,19 @@ This repository includes [TOMLMojo](https://github.com/forfudan/decimojo/tree/ma
3737

3838
DeciMojo is available in the [modular-community](https://repo.prefix.dev/modular-community) package repository. You can install it using any of these methods:
3939

40-
From the `pixi` CLI, simply run ```pixi add decimojo```. This fetches the latest version and makes it immediately available for import.
40+
1. From the `pixi` CLI, run the command ```pixi add decimojo```. This fetches the latest version and makes it immediately available for import.
4141

42-
For projects with a `mojoproject.toml`file, add the dependency:
42+
1. In the `mojoproject.toml` file of your project, add the following dependency:
4343

44-
```toml
45-
decimojo = "==0.5.0"
46-
```
44+
```toml
45+
decimojo = "==0.5.0"
46+
```
47+
48+
Then run `pixi install` to download and install the package.
4749

48-
Then run `pixi install` to download and install the package.
50+
1. For the latest development version in the `main` branch, clone [this GitHub repository](https://github.com/forfudan/decimojo) and build the package locally using the command `pixi run package`.
4951

50-
For the latest development version, clone the [GitHub repository](https://github.com/forfudan/decimojo) and build the package locally.
52+
The following table summarizes the package versions and their corresponding Mojo versions:
5153

5254
| `decimojo` | `mojo` | package manager |
5355
| ---------- | ------------- | --------------- |
@@ -56,7 +58,7 @@ For the latest development version, clone the [GitHub repository](https://github
5658
| v0.3.0 | ==25.2 | magic |
5759
| v0.3.1 | >=25.2, <25.4 | pixi |
5860
| v0.4.x | ==25.4 | pixi |
59-
| v0.5.0 | ==25.4 | pixi |
61+
| v0.5.0 | ==25.5 | pixi |
6062

6163
## Quick start
6264

@@ -77,7 +79,7 @@ This will import the following types or aliases into your namespace:
7779

7880
---
7981

80-
Here are some examples showcasing the arbitrary-precision feature of the `BigDecimal` type (`BDec`). For some mathematical operations, the default precision (number of significant digits) is set to `36`. You can change the precision by passing the `precision` argument to the function. This default precision will be configurable globally in future when Mojo supports global variables.
82+
Here are some examples showcasing the arbitrary-precision feature of the `BigDecimal` type (aliases: `BDec` and `Decimal`). For some mathematical operations, the default precision (number of significant digits) is set to `36`. You can change the precision by passing the `precision` argument to the function. This default precision will be configurable globally in future when Mojo supports global variables.
8183

8284
```mojo
8385
from decimojo.prelude import *
@@ -186,7 +188,7 @@ fn main() raises:
186188
print(a.is_zero()) # Check for zero: False
187189
188190
# === Type Conversions ===
189-
print(a.to_str()) # To string: "12345678901234567890"
191+
print(String(a)) # To string: "12345678901234567890"
190192
191193
# === Sign Handling ===
192194
print(-a) # Negation: -12345678901234567890

docs/changelog.md

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

33
This is a list of RELEASED changes for the DeciMojo Package.
44

5-
## 20250801 (v0.5.0)
5+
## 20250806 (v0.5.0)
66

7-
DeciMojo v0.5.0 introduces significant enhancements to the `BigDecimal` and `BigUInt` types, including new mathematical functions and performance optimizations. The release adds **trigonometric functions** for `BigDecimal`, implements the **Chudnovsky algorithm** for computing π, implements the **Karatsuba multiplication algorithm** and **Burnikel-Ziegler fast division algorithm** for `BigUInt`. In-place subtraction is now supported for `BigUInt`, and SIMD is utilized for arithmetic operations. The `Decimal` type is renamed to `Decimal128` to reflect its 128-bit fixed precision. The release also includes improved error handling, optimized type conversions, and comprehensive documentation updates.
7+
DeciMojo v0.5.0 introduces significant enhancements to the `BigDecimal` and `BigUInt` types, including new mathematical functions and performance optimizations. The release adds **trigonometric functions** for `BigDecimal`, implements the **Chudnovsky algorithm** for computing π, and implements the **Karatsuba multiplication algorithm** and **Burnikel-Ziegler division algorithm** for `BigUInt`. In-place operations, slice operations, and SIMD operations are now supported for `BigUInt` arithmetic. The `Decimal` type is renamed to `Decimal128` to reflect its 128-bit fixed precision. The release also includes improved error handling, optimized type conversions, refactored testing suites, and documentation updates.
88

99
DeciMojo v0.5.0 is compatible with Mojo v25.5.
1010

docs/examples_on_bigint.mojo

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from decimojo.prelude import *
2+
3+
4+
fn main() raises:
5+
# === Construction ===
6+
var a = BigInt("12345678901234567890") # From string
7+
var b = BInt(12345) # From integer
8+
9+
# === Basic Arithmetic ===
10+
print(a + b) # Addition: 12345678901234580235
11+
print(a - b) # Subtraction: 12345678901234555545
12+
print(a * b) # Multiplication: 152415787814108380241050
13+
14+
# === Division Operations ===
15+
print(a // b) # Floor division: 999650944609516
16+
print(a.truncate_divide(b)) # Truncate division: 999650944609516
17+
print(a % b) # Modulo: 9615
18+
19+
# === Power Operation ===
20+
print(BInt(2).power(10)) # Power: 1024
21+
print(BInt(2) ** 10) # Power (using ** operator): 1024
22+
23+
# === Comparison ===
24+
print(a > b) # Greater than: True
25+
print(a == BInt("12345678901234567890")) # Equality: True
26+
print(a.is_zero()) # Check for zero: False
27+
28+
# === Type Conversions ===
29+
print(String(a)) # To string: "12345678901234567890"
30+
31+
# === Sign Handling ===
32+
print(-a) # Negation: -12345678901234567890
33+
print(
34+
abs(BInt("-12345678901234567890"))
35+
) # Absolute value: 12345678901234567890
36+
print(a.is_negative()) # Check if negative: False
37+
38+
# === Extremely large numbers ===
39+
# 3600 digits // 1800 digits
40+
print(BInt("123456789" * 400) // BInt("987654321" * 200))

docs/examples_on_decimal128.mojo

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from decimojo.prelude import *
2+
3+
4+
fn main() raises:
5+
# === Construction ===
6+
var a = Dec128("123.45") # From string
7+
var b = Dec128(123) # From integer
8+
var c = Dec128(123, 2) # Integer with scale (1.23)
9+
var d = Dec128.from_float(3.14159) # From floating-point
10+
11+
# === Basic Arithmetic ===
12+
print(a + b) # Addition: 246.45
13+
print(a - b) # Subtraction: 0.45
14+
print(a * b) # Multiplication: 15184.35
15+
print(a / b) # Division: 1.0036585365853658536585365854
16+
17+
# === Rounding & Precision ===
18+
print(a.round(1)) # Round to 1 decimal place: 123.5
19+
print(a.quantize(Dec128("0.01"))) # Format to 2 decimal places: 123.45
20+
print(a.round(0, RoundingMode.ROUND_DOWN)) # Round down to integer: 123
21+
22+
# === Comparison ===
23+
print(a > b) # Greater than: True
24+
print(a == Dec128("123.45")) # Equality: True
25+
print(a.is_zero()) # Check for zero: False
26+
print(Dec128("0").is_zero()) # Check for zero: True
27+
28+
# === Type Conversions ===
29+
print(Float64(a)) # To float: 123.45
30+
print(a.to_int()) # To integer: 123
31+
print(a.to_str()) # To string: "123.45"
32+
print(a.coefficient()) # Get coefficient: 12345
33+
print(a.scale()) # Get scale: 2
34+
35+
# === Mathematical Functions ===
36+
print(Dec128("2").sqrt()) # Square root: 1.4142135623730950488016887242
37+
print(Dec128("100").root(3)) # Cube root: 4.641588833612778892410076351
38+
print(Dec128("2.71828").ln()) # Natural log: 0.9999993273472820031578910056
39+
print(Dec128("10").log10()) # Base-10 log: 1
40+
print(
41+
Dec128("16").log(Dec128("2"))
42+
) # Log base 2: 3.9999999999999999999999999999
43+
print(Dec128("10").exp()) # e^10: 22026.465794806716516957900645
44+
print(Dec128("2").power(10)) # Power: 1024
45+
46+
# === Sign Handling ===
47+
print(-a) # Negation: -123.45
48+
print(abs(Dec128("-123.45"))) # Absolute value: 123.45
49+
print(Dec128("123.45").is_negative()) # Check if negative: False
50+
51+
# === Special Values ===
52+
print(Dec128.PI()) # π constant: 3.1415926535897932384626433833
53+
print(Dec128.E()) # e constant: 2.7182818284590452353602874714
54+
print(Dec128.ONE()) # Value 1: 1
55+
print(Dec128.ZERO()) # Value 0: 0
56+
print(Dec128.MAX()) # Maximum value: 79228162514264337593543950335
57+
58+
# === Convenience Methods ===
59+
print(Dec128("123.400").is_integer()) # Check if integer: False
60+
print(a.number_of_significant_digits()) # Count significant digits: 5
61+
print(Dec128("12.34").to_str_scientific()) # Scientific notation: 1.234E+1

0 commit comments

Comments
 (0)