内容
# 浮点数转换计算器
用于转换和可视化浮点数的交互式工具,支持标准和自定义格式。在 FP32、FP16、BF16、TF32、FP8 等格式之间进行转换,同时检查二进制表示和精度损失。
**在线地址:** https://sw23.github.io/fp-conv/
## 功能特点
- **格式预设:** FP64、FP32、FP16、BF16、TF32、OCP FP4/FP6/FP8
- **整数格式:** INT32、UINT32、INT16、UINT16、INT8、UINT8、INT4、UINT4
- **OCP 格式支持:** 完全支持 Open Compute Project 微缩放格式
- **自定义格式:** 定义任意位布局(0–15 指数位,0–112 尾数位)
- **交互式编辑:** 切换个别位并查看十进制/十六进制更新
- **精度分析:** 计算格式之间的绝对和相对误差
- **特殊值:** 探索零、无穷大、NaN、非正规格数和边界情况
- **舍入模式:** 实现 IEEE 754 舍入模式(四舍五入、远离零、向零、向 +inf 和向 -inf)
- **定点模式:** 将指数位设置为 0 以表示分数
- **可分享链接:** 通过 URL 参数(输入/输出格式、值和舍入模式)收藏或分享转换结果
- **移动友好:** 适用于各种屏幕尺寸
- **WebMCP API:** AI 代理可以通过 [WebMCP](docs/webmcp.md) 执行转换
## 支持的格式
除了您可以定义的任何自定义格式(最多 15 个指数位和 112 个尾数位)之外,还支持以下标准格式。交互式页面已创建,以帮助解释和可视化每种标准格式:
- **IEEE 754:**
[FP64](https://sw23.github.io/fp-conv/formats/fp64.html),
[FP32](https://sw23.github.io/fp-conv/formats/fp32.html),
[FP16](https://sw23.github.io/fp-conv/formats/fp16.html)
- **机器学习/人工智能:**
[TF32](https://sw23.github.io/fp-conv/formats/tf32.html),
[BF16](https://sw23.github.io/fp-conv/formats/bf16.html)
- **整数:**
[INT32](https://sw23.github.io/fp-conv/formats/int32.html),
[UINT32](https://sw23.github.io/fp-conv/formats/uint32.html),
[INT16](https://sw23.github.io/fp-conv/formats/int16.html),
[UINT16](https://sw23.github.io/fp-conv/formats/uint16.html),
[INT8](https://sw23.github.io/fp-conv/formats/int8.html),
[UINT8](https://sw23.github.io/fp-conv/formats/uint8.html),
[INT4](https://sw23.github.io/fp-conv/formats/int4.html),
[UINT4](https://sw23.github.io/fp-conv/formats/uint4.html)
- **OCP 微缩放:**
[FP8 E4M3](https://sw23.github.io/fp-conv/formats/fp8-e4m3.html),
[FP8 E5M2](https://sw23.github.io/fp-conv/formats/fp8-e5m2.html),
[FP6 E2M3](https://sw23.github.io/fp-conv/formats/fp6-e2m3.html),
[FP6 E3M2](https://sw23.github.io/fp-conv/formats/fp6-e3m2.html),
[FP4 E2M1](https://sw23.github.io/fp-conv/formats/fp4-e2m1.html)
- **自定义:** 支持广泛的用户定义格式
## MCP 服务器
[`fp-conv-mcp`](https://www.npmjs.com/package/fp-conv-mcp) npm 包提供了一个本地 [Model Context Protocol](https://modelcontextprotocol.io) 服务器,为代理提供直接的本地访问浮点格式转换功能。
示例客户端配置(VS Code,`.vscode/mcp.json`):
```json
{
"servers": {
"fp-conv": {
"type": "stdio",
"command": "npx",
"args": ["-y", "fp-conv-mcp"]
}
}
}
```
参见 [软件包 README](packages/fp-conv-mcp/README.md) 以获取完整的使用方法、每个客户端的设置和调试说明。
## 命令行工具
[`fp-conv-cli`](https://www.npmjs.com/package/fp-conv-cli) npm 包提供了一个跨平台的命令行转换器版本(Windows、macOS 和 Linux),重用了与 Web 应用程序和 MCP 服务器相同的转换引擎。安装后的命令为 `fp-conv`。
```bash
npx fp-conv-cli convert 3.14 --from fp32 --to fp16
```
它支持 `encode`、`decode`、`convert`、`info` 和 `list` 命令,输出人类可读或 `--json` 格式。参见 [软件包 README](packages/fp-conv-cli/README.md) 以获取完整的使用方法和示例。
## 开发
参见 [CONTRIBUTING.md](CONTRIBUTING.md) 以获取本地设置、测试、代码检查、站点服务和 oracle 测试向量工作流的说明。
## 许可证
MIT © 2026 Spencer Williams. 参见 [LICENSE](LICENSE)。