cli/mpfr_expr_cli tutorial

This tutorial shows how to check binary against an MPFR data file from the command line. The runner is reached as floating-conformance --backend mpfr; below, mpfr abbreviates that command.

I want toUse
run the committed elementary matrixmpfr FILE
run square-root or power datathe same command; the format is detected
get machine-readable output--json
call the runner from MoonBit@mpfr_expr_cli.run
run all binary corporajust conformance run binary

Quick start

The executable is built from a checkout of the repository:

just conformance build binary
_build/conformance/mpfr/native/release/build/mpfr-conformance.exe \
  --backend mpfr testdata/binary/mpfr-4.2.2-elementary.txt
MPFR elementary summary
cases: …
passed cases: …
failed cases: 0

From MoonBit code

The runner is also a library. The package belongs to the tools module Luna-Flow/floating-tools (directory tooling/ of the repository, versioned with the library), not to the published library. Write your code as a package of this workspace or, once the tools module is published, run moon add Luna-Flow/floating-tools@0.11.0. Import "Luna-Flow/floating-tools/cli/mpfr_expr_cli" in moon.pkg and call run:

///|
test "run the MPFR runner from MoonBit code" {
  let status = @mpfr_expr_cli.run([
    "mpfr", "--json", "../testdata/binary/smoke/mpfr-hex-sqrt.txt",
  ])
  inspect(status, content="0")
}

just docs runs the tests of this page in the module directory tooling/, so the corpus paths start with ../testdata; use your own paths in your code.

Everyday tasks

Run each format

The runner reads exactly one file and picks the format from its content:

mpfr testdata/binary/mpfr-4.2.2-elementary.txt   # contains "mpfr-elementary-v1"
mpfr pow_si.txt                                     # header contains "input_coefficient_hex"
mpfr path/to/mpfr/tests/data/sqrt                   # anything else: sqrt data_check

JSON for scripts

mpfr --json testdata/binary/mpfr-4.2.2-elementary.txt

prints one object with corpus, totalCases, passedCases, failedCases and failedIds.

Going further

  • just conformance run binary runs the pinned MPFR square-root data and the elementary matrix together with the TestFloat matrix.
  • New elementary data is produced by tools/generate_mpfr_elementary_oracle.c; keep the mpfr-elementary-v1 marker line so the runner detects the format.
  • mpfr_expr tutorial explains the row formats and pass rules.

Common pitfalls

  • One file per invocation. Extra paths, missing paths, and the shard options all print the usage line and exit with 2.
  • A lone option is read as a path. mpfr --help reports cannot read file: --help, not the usage line.
  • Format detection is textual. A square-root file that happens to contain input_coefficient_hex in a comment is parsed as power data.

Next steps