Visible to Intel only — GUID: qec1622222606456
Ixiasoft
Visible to Intel only — GUID: qec1622222606456
Ixiasoft
8.2.1. Arbitrary Precision Fixed-Point Literals in Operations
When you use the ac_fixed datatype to declare literals in your component, the compiler expands the literal, regardless of the size you set for the ac_fixed literal. To keep the compiler from expanding the literal, cast the literal to an ac_fixed data type.
Using Fixed12 = ac_fixed<12, 6, true>;
component Fixed12 threshold_vanilla(Fixed12 a){
if (a < 12.7) {
return a;
} else {
return 12.7;
}
}
In this code snippet, the 12-bit ac_fixed value is compared with 12.7. The literal 12.7 is treated as a double, with value 12.699999…. This literal is converted to a fixed-point to be compared with a, but because the literal is unconstrained, the compiler chooses a large fixed-point value and this can result in a large comparison:
Using Fixed12 = ac_fixed<12, 6, true>;
component Fixed12 threshold_cast(Fixed12 a){
if (a < (Fixed12)12.7) {
return a;
} else {
return 12.7;
}
}
<quartus_installdir>//hls/examples/tutorials/best_practices/single_vs_double_precision_math