VDSP 提供 float_to_fr16 與 fr16_to_float 兩個轉換函數,均為軟體模擬,非單週期指令。
fract32,再算術右移 16 位得 fract16。x >= 1.0 或 NaN/+Inf → 0x7FFFx < -1.0 或 -NaN/-Inf → 0x8000|x| < 3.05e-5 → 0fract16 視為 short 轉 float,再指數減 15 模擬除以 32768。編譯器支援後綴:fract16 r = 0.2r16; 自動編譯期轉為 0x1999。
float r;
fract16 r1 = 0.2r16;
r = r1; // 錯誤!r 變為 6553 (0x1999 視為整數)
fract16 非內建型別(typedef short),編譯器**不會**自動插入轉換函數。所有運算、轉換必須顯式呼叫對應函數。