C++ Arbitrary Precision Fixed-Point Types: Reference Information - 2023.2 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
Release Date
2023.2 English
Important: The arbitrary precision fixed-point types require the header file ap_fixed.h to be included in the code.

This section includes comprehensive information on the methods, synthesis behavior, and all aspects of using the ap_(u)fixed<N> arbitrary precision fixed-point data types.

  • Techniques for assigning constant and initialization values to arbitrary precision integers (including values greater than 1024-bit).
  • A detailed description of the overflow and saturation modes.
  • A description of Vitis HLS helper methods, such as printing, concatenating, bit-slicing and range selection functions.
  • A description of operator behavior, including a description of shift operations (a negative shift values, results in a shift in the opposite direction).

Vitis HLS supports fixed-point types that allow fractional arithmetic to be easily handled. The advantage of fixed-point arithmetic is shown in the following example.

ap_fixed<11, 6> Var1 = 22.96875; // 11-bit signed word, 5 fractional bits
ap_ufixed<12,11> Var2 = 512.5; // 12-bit word, 1 fractional bit
ap_fixed<16,11> Res1; // 16-bit signed word, 5 fractional bits

Res1 = Var1 + Var2; // Result is 535.46875

Even though Var1 and Var2 have different precisions, the fixed-point type ensures that the decimal point is correctly aligned before the operation (an addition in this case), is performed. You are not required to perform any operations in the C code to align the decimal point.

The type used to store the result of any fixed-point arithmetic operation must be large enough (in both the integer and fractional bits) to store the full result.

If this is not the case, the ap_fixed type performs:

  • overflow handling (when the result has more MSBs than the assigned type supports)
  • quantization (or rounding, when the result has fewer LSBs than the assigned type supports)

The ap_[u]fixed type provides various options on how the overflow and quantization are performed. The options are discussed below.