Skip to content

Commit 7a03f9e

Browse files
Update decimo (#230)
Co-authored-by: Caroline Frasca <42614552+carolinefrasca@users.noreply.github.com>
1 parent a6887c1 commit 7a03f9e

2 files changed

Lines changed: 31 additions & 19 deletions

File tree

recipes/decimo/README.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,33 @@
44

55
An arbitrary-precision integer and decimal library for [Mojo](https://www.modular.com/mojo), inspired by Python's `int` and `Decimal`.
66

7-
**[中文·漢字](https://github.com/forfudan/decimo/blob/main/docs/readme_zht.md)** | **[Changelog](https://github.com/forfudan/decimo/blob/main/docs/changelog.md)** | **[Repository on GitHub»](https://github.com/forfudan/decimo)** | **[Discord channel»](https://discord.gg/3rGH87uZTk)**
8-
9-
- [Overview](#overview)
10-
- [Installation](#installation)
11-
- [Quick start](#quick-start)
12-
- [Objective](#objective)
13-
- [Status](#status)
14-
- [Tests and benches](#tests-and-benches)
15-
- [Citation](#citation)
16-
- [License](#license)
7+
[![Version](https://img.shields.io/github/v/tag/forfudan/decimo?label=version&color=blue)](https://github.com/forfudan/decimo/releases)
8+
[![pixi](https://img.shields.io/badge/pixi%20add-decimo-purple)](https://prefix.dev/channels/modular-community/packages/decimo)
9+
[![CI](https://img.shields.io/github/actions/workflow/status/forfudan/argmojo/run_tests.yaml?branch=main&label=tests)](https://github.com/forfudan/argmojo/actions/workflows/run_tests.yaml)
10+
[![Last Commit](https://img.shields.io/github/last-commit/forfudan/argmojo?color=red)](https://github.com/forfudan/argmojo/commits/main)
11+
12+
<!--
13+
[![Mojo](https://img.shields.io/badge/mojo-0.26.1-orange)](https://docs.modular.com/mojo/manual/)
14+
[![License](https://img.shields.io/github/license/forfudan/argmojo)](LICENSE)
15+
[![Stars](https://img.shields.io/github/stars/forfudan/argmojo?style=flat)](https://github.com/forfudan/argmojo/stargazers)
16+
[![Issues](https://img.shields.io/github/issues/forfudan/argmojo)](https://github.com/forfudan/argmojo/issues)
17+
![Platforms](https://img.shields.io/badge/platform-macOS%20%7C%20Linux-lightgrey)
18+
-->
19+
20+
<!--
21+
[![中文](https://img.shields.io/badge/中文-介紹-red)](https://github.com/forfudan/decimo/blob/main/docs/readme_zht.md)
22+
[![Changelog](https://img.shields.io/badge/change-log-yellow)](https://github.com/forfudan/decimo/blob/main/docs/changelog.md)
23+
[![Repository on GitHub](https://img.shields.io/badge/repo-GitHub-black)](https://github.com/forfudan/decimo)
24+
[![Discord](https://img.shields.io/badge/discord-join-darkblue)](https://discord.gg/3rGH87uZTk)
25+
-->
1726

1827
## Overview
1928

2029
Decimo provides an arbitrary-precision integer and decimal library for Mojo. It delivers 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.
2130

2231
For Pythonistas, `decimo.BInt` to Mojo is like `int` to Python, and `decimo.Decimal` to Mojo is like `decimal.Decimal` to Python.
2332

24-
The core types are:
33+
The core types are[^auxiliary]:
2534

2635
- An arbitrary-precision signed integer type `BInt`[^bigint], which is a Mojo-native equivalent of Python's `int`.
2736
- An arbitrary-precision decimal implementation (`Decimal`) allowing for calculations with unlimited digits and decimal places[^arbitrary], which is a Mojo-native equivalent of Python's `decimal.Decimal`.
@@ -33,11 +42,13 @@ The core types are:
3342
| `Decimal` | `BDec`, `BigDecimal` | Equivalent to Python's `decimal.Decimal` | Base-10^9 |
3443
| `Dec128` | `Decimal128` | 128-bit fixed-precision decimal type | Triple 32-bit words |
3544

36-
The auxiliary types include a base-10 arbitrary-precision signed integer type (`BigInt10`) and a base-10 arbitrary-precision unsigned integer type (`BigUInt`) supporting unlimited digits[^bigint10]. `BigUInt` is used as the internal representation for `BigInt10` and `Decimal`.
45+
---
46+
47+
**Decimo** combines "**Deci**mal" and "**Mo**jo" - reflecting its purpose and implementation language. "Decimo" is also a Latin word meaning "tenth" and is the root of the word "decimal".
3748

3849
---
3950

40-
**Decimo** combines "**De**cimal" and "**Mo**jo" - reflecting its purpose and implementation language. "Decimo" is also a Latin word meaning "tenth" and is the root of the word "decimal".
51+
This repository includes a built-in [TOML parser](./docs/readme_toml.md) (`decimo.toml`), a lightweight pure-Mojo implementation supporting TOML v1.0. It parses configuration files and test data, supporting basic types, arrays, and nested tables. While created for Decimo's testing framework, it offers general-purpose structured data parsing with a clean, simple API.
4152

4253
## Installation
4354

@@ -93,7 +104,7 @@ This will import the following types or aliases into your namespace:
93104

94105
---
95106

96-
Here are some examples showcasing the arbitrary-precision feature of the `Decimal` type. 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.
107+
Here are some examples showcasing the arbitrary-precision feature of the `Decimal` type. For some mathematical operations, the default precision (number of significant digits) is set to `28`. 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.
97108

98109
```mojo
99110
from decimo.prelude import *
@@ -109,7 +120,7 @@ fn main() raises:
109120
print(a + b) # 123458023.691346789
110121
print(a - b) # 123455554.555566789
111122
print(a * b) # 152415787654.32099750190521
112-
print(a.true_divide(b + 1)) # 99919.0656560820700835791386582569736
123+
print(a.true_divide(b + 1)) # 99919.06565608207008357913866
113124
114125
# === Exponential Functions === #
115126
print(a.sqrt(precision=80))
@@ -332,5 +343,6 @@ This repository and its contributions are licensed under the Apache License v2.0
332343

333344
[^fixed]: The `Decimal128` 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`), Decimo 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). Decimo's `Decimal128` type is similar to `System.Decimal` (C#/.NET), `rust_decimal` in Rust, `DECIMAL/NUMERIC` in SQL Server, etc.
334345
[^bigint]: The `BigInt` implementation uses a base-2^32 representation with a little-endian format, where the least significant word is stored at index 0. Each word is a `UInt32`, allowing for efficient storage and arithmetic operations on large integers. This design choice optimizes performance for binary computations while still supporting arbitrary precision.
346+
[^auxiliary]: The auxiliary types include a base-10 arbitrary-precision signed integer type (`BigInt10`) and a base-10 arbitrary-precision unsigned integer type (`BigUInt`) supporting unlimited digits[^bigint10]. `BigUInt` is used as the internal representation for `BigInt10` and `Decimal`.
335347
[^bigint10]: The BigInt10 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.
336348
[^arbitrary]: Built on top of our completed BigInt10 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.

recipes/decimo/recipe.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
context:
2-
version: "0.8.0"
3-
mojo_version: "=0.26.1"
2+
version: "0.9.0"
3+
mojo_version: "=0.26.2"
44

55
package:
66
name: "decimo"
77
version: ${{ version }}
88

99
source:
1010
- git: https://github.com/forfudan/decimo.git
11-
rev: b572a44aa0623f85cc9a7c94d1bef4ffe718f273
11+
rev: 1132e59aec2b8a586431728cd9760b5a72dcbbb8
1212

1313
build:
1414
number: 0
@@ -28,7 +28,7 @@ about:
2828
homepage: https://github.com/forfudan/decimo
2929
license: Apache-2.0
3030
license_file: LICENSE
31-
summary: An arbitrary-precision decimal and integer library for Mojo
31+
summary: An arbitrary-precision integer and decimal library for Mojo
3232
repository: https://github.com/forfudan/decimo.git
3333

3434
extra:

0 commit comments

Comments
 (0)