-
Notifications
You must be signed in to change notification settings - Fork 0
Rounding
When converting or quantizing numbers (like converting a high-precision Fix_18_17 signal down to Fix_8_7 in FPGA design, or floating-point rounding), rounding modes define how you resolve values that fall between two integers or quantum steps.The main difference between these modes lies in how they handle exact midpoints (like
Value, Round to Even, Round to Odd, Round to Zero, Round to +∞, Round Half Up, Round Half Down +1.4, +1, +1, +1, +2 (if ceiling) / +1, +1, +1
+1.5, +2,+1,+1,+2,+2,+1
+2.5, +2,+3,+2,+3,+3,+2
−1.5, −2,−1,−1,−1,−1,−2
−2.5, −2,−3,−2,−2,−2,−3
- Round to Even (Convergent Rounding / Banker's Rounding)How it works: Rounds to the nearest number. If the value is exactly halfway (e.g.,
$.5$ ), it rounds to the nearest even integer.Key Feature: Zero DC Bias. Because midpoints end in an even integer 50% of the time and an odd integer 50% of the time, the rounding errors cancel out statistically over large datasets.Best Use Case: DSP, Financial Applications, IEEE 754 Floating-Point standard default. Highly recommended for DSP/FPGA datapath quantization to prevent cumulative offset errors.
-
Round to OddHow it works: Rounds to the nearest number. If the value is exactly halfway, it rounds to the nearest odd integer.Key Feature: Also bias-free across large datasets, but less common in general computing than Round to Even.Best Use Case: Specialized arithmetic or systems designed to avoid zero-valued outputs in specific boundary conditions.
-
Round to Zero (Truncation / Directed Rounding) How it works: Simply drops the fractional part (chops off the LSBs toward zero). positive numbers move down toward zero, negative numbers move up toward zero.Key Feature: Extremely cheap hardware implementation (requires no adder logic). However, it squeezes values toward zero, shrinking magnitude.Best Use Case: Fixed-point code conversions, integer division in C/C++ ((int)x).
-
Round to
$+\infty$ (Ceiling / Directed Rounding) How it works: Always rounds UP toward positive infinity, regardless of the fractional value.Key Feature: Moves all numbers to the right on the number line. Introduces a positive DC bias.Best Use Case: Interval arithmetic, buffer allocation sizing (ensuring you allocate enough space/memory)."Nearest Neighbor" Tie-Breaking ModesThese three modes round to the nearest number for non-midpoints, but differ in how they break the tie at exact$.5$ midpoints: -
Round Half Up (Nearest, Ties Away From Zero / Commercial Rounding) How it works: If halfway, rounds away from zero toward the larger magnitude (
$+1.5 \rightarrow +2$ ,$-1.5 \rightarrow -2$ ).Key Feature: This is the standard "schoolbook" rounding taught in elementary math.Drawback: Introduces a slight positive magnitude bias because midpoints always push away from zero. -
Round Half Down (Nearest, Ties Toward Zero) How it works: If halfway, rounds toward zero (
$+1.5 \rightarrow +1$ ,$-1.5 \rightarrow -1$ ).Key Feature: The exact inverse of Round Half Up. Shrinks magnitude at midpoints. -
Refer to casper's library block, "convert".