Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
e3141b8
[float][gmp] Add planning for GMP integration + Initialize folders an…
forfudan Apr 3, 2026
f0fd648
[float][gmp] Implement most of the methods for `BigFloat` (#191)
forfudan Apr 7, 2026
6e100e8
[cli] Update codebase to argmojo v0.5.0 and use declarative API (#192)
forfudan Apr 7, 2026
b989278
[doc] Add enhancement plan for `Decimal128` type (#193)
forfudan Apr 8, 2026
6b9d43c
[docstring] Ensure that all functions, fields, and constants have doc…
forfudan Apr 8, 2026
dc682be
[error] Improve display of error messages (colours, auto-inferred fil…
forfudan Apr 9, 2026
78b0c9c
[error] Make `message` and `function` fields mandatory for `DecimoErr…
forfudan Apr 9, 2026
2cf5e0f
[error] Remove redundant `Error` wrappers + Add `RuntimeError` type +…
forfudan Apr 9, 2026
b5567d9
[docstring][error] Fixes `raises:` sections in docstrings across code…
forfudan Apr 9, 2026
5aa3550
[error] Use shortened and relative paths for files that raise errors …
forfudan Apr 10, 2026
8ee0b4c
[cli] Allow negative numbers + add range, value name, argument group …
forfudan Apr 10, 2026
7f51854
[cli] Enable negative expressions as positional arguments (#202)
forfudan Apr 10, 2026
2c484de
[cli] Make all short names upper cases + Enable pipe mode and file mo…
forfudan Apr 11, 2026
d8865df
[cli][doc] Add benchmarks against bc and python + Add shell completio…
forfudan Apr 11, 2026
76f1c0b
[cli] Add interactive REPL (#205)
forfudan Apr 12, 2026
970cc43
[cli] Add `ans` variable + variable assignment and evaluation (#206)
forfudan Apr 14, 2026
910423e
[doc][repo] Update documents + Re-organize "docs" folder (#207)
forfudan Apr 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
373 changes: 312 additions & 61 deletions .github/workflows/run_tests.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ kgen.trace.json*
local
# CLI binary
/decimo
# Compiled GMP/MPFR wrapper (built from source)
*.dylib
*.so
# Python build artifacts
*.so
__pycache__/
Expand Down
26 changes: 26 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Decimo
Copyright 2025 Yuhao Zhu

Licensed under the Apache License, Version 2.0.


Third-Party Dependencies
========================

Decimo optionally uses the following libraries at runtime, if installed by
the user. Decimo does not include, copy, or distribute any source code or
binaries from these projects.

GNU MPFR Library (https://www.mpfr.org/)
Copyright (C) Free Software Foundation, Inc.
Licensed under the GNU Lesser General Public License v3.0 or later (LGPLv3+).

GNU Multiple Precision Arithmetic Library (GMP) (https://gmplib.org/)
Copyright (C) Free Software Foundation, Inc.
Licensed under the GNU Lesser General Public License v3.0 or later (LGPLv3+),
or the GNU General Public License v2.0 or later (GPLv2+).

MPFR and GMP are loaded at runtime via dlopen/dlsym when the user has
independently installed them (e.g. `brew install mpfr` on macOS or
`apt install libmpfr-dev` on Linux). The BigFloat type requires MPFR;
all other Decimo types work without any external dependencies.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ The core types are[^auxiliary]:
| Type | Other names | Information | Internal representation |
| --------- | -------------------- | ---------------------------------------- | ----------------------- |
| `BInt` | `BigInt` | Equivalent to Python's `int` | Base-2^32 |
| `Decimal` | `BDec`, `BigDecimal` | Equivalent to Python's `decimal.Decimal` | Base-10^9 |
| `Decimal` | `BigDecimal`, `BDec` | Equivalent to Python's `decimal.Decimal` | Base-10^9 |
| `Dec128` | `Decimal128` | 128-bit fixed-precision decimal type | Triple 32-bit words |

---

**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".

---
A CLI calculator tool, built on top of the Decimo library and powered by [ArgMojo](https://github.com/forfudan/argmojo) (a command-line argument parser library), is also available in this repository. It provides a convenient way to perform high-precision calculations directly from the command line.

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.

Expand Down Expand Up @@ -96,7 +94,7 @@ from decimo import *
This will import the following types or aliases into your namespace:

- `BInt` (alias of `BigInt`): An arbitrary-precision signed integer type, equivalent to Python's `int`.
- `Decimal` or `BDec` (aliases of `BigDecimal`): An arbitrary-precision decimal type, equivalent to Python's `decimal.Decimal`.
- `Decimal` (also available as `BigDecimal` or `BDec`): An arbitrary-precision decimal type, equivalent to Python's `decimal.Decimal`.
- `Dec128` (alias of `Decimal128`): A 128-bit fixed-precision decimal type.
- `RoundingMode`: An enumeration for rounding modes.
- `ROUND_DOWN`, `ROUND_HALF_UP`, `ROUND_HALF_EVEN`, `ROUND_UP`: Constants for common rounding modes.
Expand All @@ -110,10 +108,10 @@ from decimo.prelude import *


fn main() raises:
var a = BDec("123456789.123456789") # BDec is an alias for BigDecimal
var a = Decimal("123456789.123456789")
var b = Decimal(
"1234.56789"
) # Decimal is a Python-like alias for BigDecimal
)

# === Basic Arithmetic === #
print(a + b) # 123458023.691346789
Expand Down Expand Up @@ -344,4 +342,4 @@ This repository and its contributions are licensed under the Apache License v2.0
[^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.
[^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`.
[^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.
[^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.
[^arbitrary]: Built on top of our completed BigInt10 implementation, Decimal supports arbitrary precision for both the integer and fractional parts, similar to `decimal` and `mpmath` in Python, `java.math.BigDecimal` in Java, etc.
Loading
Loading