Explicit Conversions of ap_[u]fixpt
(Ask a Question)There are several functions to explicitly convert
ap_[u]fixpt
types into
other types, besides value based assignments. The raw_bits
function
produces a uint of the same width as the ap_[u]fixpt with the same raw data, and to_double
returns a double representing the value of the ap_[u]fixpt. Note that for wide enough
ap_[u]fixpt to_double can lose precision, and can be inefficient in hardware. These are
demonstrated in the following code
snippet.#include "hls/ap_fixpt.hpp" #include <iostream> #include <stdio.h> using namespace hls;
//... ap_fixpt<12, 5> ffixed("898"); ap_uint<12> logical_fixed = ffixed.raw_bits(); logical_fixed == 0x898; // true double double_fixed = ffixed.to_double(); double_fixed == -14.8125; // true