Skip to content
This repository was archived by the owner on Nov 22, 2026. It is now read-only.

mojo-pyformat v0.2.0

Choose a tag to compare

@amarbarosys amarbarosys released this 05 Nov 11:03
· 10 commits to main since this release

mojo-pyformat v0.2.0

Released: 2026-11-04 · Tag: v0.2.0 · Previous: v0.1.2

What it does

Python's format() for numbers in Mojo, with the same digits: {:.Nf}, thousands separators, g, e, and %, rounded on the double's exact binary value as CPython does.

Highlights

  • py_repr(x): Python repr(float) digit for digit. Mojo 1.2's own float printing is not round-trip safe (it prints two different doubles as 3.000000005061751e+16 and writes e+015); this is the fix when text must equal Python.

Changes

Added

  • py_repr, with 653 repr rows in the oracle grid; whole numbers below 1e16 take an exact fast path.

Verified

Check Result
scripts/ci.sh (15,511 lines vs Python 3.14 format and repr, every power of two included, plus 43,660 wide lines with 804 repr on random bits and subnormals) on Mojo 1.2.0; scripts/check.sh on 1.3.0.dev2026110305 PASS

Known limits

  • py_repr tries up to 17 precisions with atof for non-integral values, about 1 µs each; fine for output text, not for hot loops.

Upgrade / run

from pyformat import py_repr

Commits

  • All commits from v0.1.2 to tag v0.2.0: git log v0.1.2..v0.2.0.