You're reading an pre-release version of this documentation.
For the latest stable release version, please have a look at master.

Function fp32_to_fp16

Function Documentation

uint16_t fp32_to_fp16(float f)

将 float32 按 IEEE-754 binary32 格式转换为 binary16(半精度)表示的位模式。

该函数将 32 位浮点数 float 的二进制表示压缩为 16 位浮点数(half-precision), 并返回其对应的 uint16_t 位模式表示,**不进行实际浮点运算**,只做位级转换。

常用于将神经网络模型中的参数或中间值从 float32 转为 float16 格式,以节省存储或加速推理。

备注

本实现来源:njuffa,Stack Overflow (2023),用于高效 float → half 位编码转换。 参考链接:https://stackoverflow.com/a/16593965

参数:

f -- [IN] 原始的 float32 浮点数。

返回:

uint16_t 对应的 IEEE-754 binary16 编码的位模式。