Decimo just hit v0.10.0 (Mojo v1.0.0b1)

Version Mojo pixi

Hi Mojicians,

Decimo (formerly DeciMojo) just hit v0.10.0 (compatible with Mojo v1.0.0b1) and can be installed via pixi add decimo. In this release, I tried out something new. Here are the highlights:

  1. A new REPL mode has been added to the CLI calculator. The calculator can now be installed via brew install forfudan/tap/decimo.
  2. The Decimal128 (128-bit fixed precision decimal type) has been greatly optimised.
  3. A new BigFloat type backed by MPFR for arbitrary-precision calculations has been added into the core library.

Let me walk through each.

CLI calculator — REPL and brew install

In v0.9.0 the CLI calculator was a proof of concept with a command-line interface. v0.10.0 adds REPL mode into it. You can now run decimo with no arguments to enter the REPL mode, and then evaluate expressions interactively with line editing, history, and live settings toggling.

One useful design point is the settings system. Any command-line flag you can pass to decimo can also be toggled live in the REPL with a : command, in a very convenient syntax. For example, :50 s hd sets the precision to 50 digits, switches to scientific notation, and uses the “half down” rounding mode.

If the setting is written in-line (e.g. :p 50), the setting is applied on the spot. It it is written as a standalone line, the setting is applied from onwards. This allows to to easily control the precision and formatting of your results.

The decimo calculator can be installed via a Homebrew tap:

% brew install forfudan/tap/decimo

Decimal128 — optimised and feature-complete

Decimal128 is the fixed-128-bit decimal type (up to 28 fractional digits and significant digits). It is the oldest type in Decimo (came with v0.1.0 on 8 March 2025). v0.10.0 gave it both a feature push and a performance push:

  • New methods matching Python’s decimal.Decimal and IEEE 754: fma() (single-rounded fused multiply-add), __divmod__(), from_decimal(BigDecimal), cbrt(), normalize(), __hash__(), same_quantum(), max / min / clamp, trunc / floor / ceil / fract / signum / unpack, __bool__ / __pos__, plus a unified to_string(scientific=…, engineering=…, delimiter=…) API.

  • Optimised core functions: add, subtract, multiply, divide, exp, ln, log10, from_string, to_string, etc.

A cross-language benchmark is included in this release, comparing Decimo against Rust (rust_decimal), C# (System.Decimal), and VB.NET, with BigDecimal acting as the high-precision reference. The results show that decimo is as fast as other languages in decimal128 performance and wins in ULP (units in the last place) accuracy.

BigFloat — arbitrary-precision binary float powered by MPFR

This is the new core type in v0.10.0. BigFloat wraps MPFR (the GNU library for correctly-rounded arbitrary-precision floating point) through a thin C wrapper. Every arithmetic, transcendental, and rounding operation is a single MPFR call against a pooled mpfr_t handle:

from decimo import BigFloat, BFlt
var x = BigFloat("2", precision=100)
var y = x.sqrt()
var z = (BigFloat.pi(precision=100) * x).sin()

BigFloat is optional: it requires MPFR/GMP on the user’s system, and you opt in with pixi run buildgmp to compile the C wrapper.

At the current stage, compiling a mojo file with BigFloat is not very convenient because you have to compile the C wrapper first and then build the mojo file with linking against the C wrapper. I wrote a sh script to allow a quick build and run your mojo script via a simple pixi command.

pixi run bf file_name.mojo

This will automatically compile the wrapper and link it for you mojo file.

Other Changes

  • New Rational type — exact rational number, stored as a reduced fraction of two Integers.
  • BigDecimal operator semantics are now aligned with Python’s decimal.Decimal: +, -, * round HALF_EVEN to the default precision (PRECISION = 28); explicit-precision add(other, precision=0) / subtract(...) / multiply(...) give callers an exact path.
  • Error system is improved — concrete RuntimeError and friends replace the catch-all DecimoError; coloured messages with auto-inferred file name and line number; shortened relative paths to preserve user privacy at compile time.

The full changelog can be found at github.com/forfudan/decimo/releases

As always, feedback and issues are welcome on the repo. Happy hacking! :fire:

Super cool!

Very cool! I think a lot of folks will find support for these types helpful. I appreciate your documentation of open issues and todos too. Great to see that you’ve been maintaining and extending this project.

Thank you :smiley:

Thank you! I would say that adding something new into decimo has actually been one of the more relaxing and interesting things for me over the past year :smiley:

Was waiting for BigFloat :slight_smile: Super cool.

Thanks. At the current stage it is not very convenient because you have to compile the C wrapper first and then build the mojo file with linking against the C wrapper.

I wrote a sh script to allow a quick build and run at the root path of the repo.

pixi run bf file_name.mojo