cli/mpfr_expr_cli 教程
本教程介绍如何在命令行中用 MPFR 数据文件检验 binary。该运行器通过 floating-conformance --backend mpfr 调用;下文以 mpfr 简称这条命令。
| 我想要 | 使用 |
|---|---|
| 运行已提交的初等函数矩阵 | mpfr FILE |
| 运行平方根或幂的数据 | 同一命令;格式会被自动检测 |
| 获取机器可读的输出 | --json |
| 从 MoonBit 调用运行器 | @mpfr_expr_cli.run |
| 运行所有二进制语料 | just conformance run binary |
快速入门
该可执行文件需从仓库的检出副本构建:
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
从 MoonBit 代码调用
运行器同时也是一个库。该包属于工具模块 Luna-Flow/floating-tools(仓库中的 tooling/ 目录,与库同版本),而不属于已发布的库。请把你的代码写成本工作区中的一个包;工具模块发布后,也可以运行 moon add Luna-Flow/floating-tools@0.11.0。 在 moon.pkg 中导入 "Luna-Flow/floating-tools/cli/mpfr_expr_cli" 并调用 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 在模块目录 tooling/ 中运行本页的测试,所以语料路径以 ../testdata 开头;在你自己的代码中请使用你自己的路径。
日常任务
运行各种格式
运行器只读取一个文件,并根据其内容选择格式:
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
mpfr --json testdata/binary/mpfr-4.2.2-elementary.txt
打印一个包含 corpus、totalCases、passedCases、failedCases 和 failedIds 的对象。
深入了解
just conformance run binary将固定版本的 MPFR 平方根数据、初等函数矩阵与 TestFloat 矩阵一起运行。- 新的初等函数数据由
tools/generate_mpfr_elementary_oracle.c生成;请保留mpfr-elementary-v1标记行,以便运行器识别格式。 - mpfr_expr 教程 解释了行格式与通过规则。
常见陷阱
- 每次调用只处理一个文件。 多余的路径、缺失的路径以及分片选项,都会打印用法行并以
2退出。 - 单独的选项会被当作路径读取。
mpfr --help报告的是cannot read file: --help,而不是用法行。 - 格式检测基于文本。 若平方根文件恰好在注释中包含
input_coefficient_hex,它会被当作幂运算数据解析。