Altifigence Academy

3 / 20 · Concept

Fixed-point output policy

Separate input scale, negative rounding, saturation and wraparound.

Bits store an integer; scale supplies meaning

Represent x as an integer X and F fractional bits, so x=X/2^F. We use the same F for A and B. Their product and accumulator have 2F fractional bits. Converting the final raw sum S back to the input scale requires division by 2^F. Convert once after the complete reduction; rounding every term first can discard contributions that would become significant together.

For F=4, [1.5,−0.5] is stored as [24,−8] and [0.25,2.0] as [4,32]. The raw dot product is 24×4−8×32=−160. Its real value is −160/256=−0.625, and its output integer at F=4 is −10.

Test negative rounding explicitly

For S=−17 and F=4, the exact output integer is −1.0625. An arithmetic right shift yields −2; truncation toward zero yields −1. Round-to-nearest, ties-to-even also yields −1. Thus an arithmetic shift is not interchangeable with every interpretation of “discard the fraction.” At the halfway values −24/16=−1.5 and −40/16=−2.5, ties-to-even selects −2 in both cases.

Our default conversion rounds the complete sum to nearest, ties to even, then saturates to the output width. On the absolute magnitude, compute quotient q and remainder r. Increment q when r exceeds half the divisor, or when it equals half and q is odd. Restore the original sign afterward. In RTL, taking the absolute value of the most negative number needs a wider temporary; the Node reference uses BigInt.

Define overflow at the output

Signed eight-bit output covers −128..127. A rounded value of 130 saturates to 127 or wraps to −126. A value of −130 saturates to −128 or wraps to 126. Either policy can be intentional, but it must be named and tested.

Compare the raw accumulator and converted output separately. A wrong raw sum points toward arithmetic or scheduling; a correct sum with a wrong output points toward scale, rounding or saturation. Preserve hand-calculated boundary cases so the reference and RTL cannot both hide the same conversion mistake.

Try it yourself

Find the ties-to-even result for F=4, S=−56, and the saturated eight-bit output for F=4, S=−2080.

Read the explanation

−56/16=−3.5 rounds to the even integer −4. −2080/16=−130, which saturates to −128 after rounding.

Your choice applies to this browser. Change it any time using the footer.