This repository was archived by the owner on Nov 22, 2026. It is now read-only.
Repository navigation
mojo-pyformat v0.1.0
mojo-pyformat v0.1.0
Released: 2026-10-21 · Commit: a66c107 · Previous: first release
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
- Identical to Python on 10,846 cases and on a wider 42,856-case set (random bit patterns, subnormals, precision up to 100, numbers to 1.8e308).
.2fis 5.9x faster than Python (1M values: 40 ms vs 234 to 242 ms);gandeabout 2x.format(2.675, '.2f')gives2.67, as Python does, because the stored double is just under 2.675.
Changes
First public release, no earlier version.
Verified
| Check | Result |
|---|---|
scripts/check.sh: 10,846 cases vs Python format() |
PASS all |
tools/oracle_wide.py in scripts/ci.sh: 42,856 cases |
identical |
scripts/ci.sh on a pristine Ubuntu 24.04.5 VM (Python 3.12.3) |
PASS all |
Known limits
- Specs outside the supported grammar raise:
+/space sign,0padding,#,_, upper-case types,,on a float. - Peak memory is the Mojo runtime's floor, about 2 MB above Python.
Upgrade / run
git clone https://github.com/amarbaro/mojo-pyformat && cd mojo-pyformat && uv sync
mojo run -I src examples/quickstart.mojo
Commits
a66c107docs(pyformat): README, api, design, agent skill, CI script and workflow14eeee6bench(pyformat): 1M values as .2f, g, .3e against Python format()968f2aafeat(pyformat): f, e, g, % and int commas, exact on the binary value9c415f2test(pyformat): Python format() oracle, 10,846 value x spec cases5dd7dfachore: repo layout, Apache-2.0, mojo>=1.1