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

mojo-pyformat v0.1.0

Choose a tag to compare

@amarbarosys amarbarosys released this 21 Oct 07:18
· 23 commits to main since this release

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).
  • .2f is 5.9x faster than Python (1M values: 40 ms vs 234 to 242 ms); g and e about 2x.
  • format(2.675, '.2f') gives 2.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, 0 padding, #, _, 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

  • a66c107 docs(pyformat): README, api, design, agent skill, CI script and workflow
  • 14eeee6 bench(pyformat): 1M values as .2f, g, .3e against Python format()
  • 968f2aa feat(pyformat): f, e, g, % and int commas, exact on the binary value
  • 9c415f2 test(pyformat): Python format() oracle, 10,846 value x spec cases
  • 5dd7dfa chore: repo layout, Apache-2.0, mojo>=1.1