Rounding (source code)

= Rounding

<Rounding> replaces a number by a permitted representable value according to a specified rule. Rounding to nearest minimizes <absolute error>; directed rounding instead selects the next permitted value toward positive infinity, negative infinity or zero. A tie between equally near values needs an explicit convention.

On the decimal grid with spacing $0.1$, $1.26$ rounds to nearest as $1.3$, with error $0.04$. Rounding to nearest has error at most half the grid spacing. In normal <floating-point arithmetic>, that spacing depends on magnitude, leading to a relative-error bound described by <unit roundoff>. The IEEE round-to-nearest-even rule resolves ties by an even final significand digit.<IEEE arithmetic in Oracle's Numerical Computation Guide>[Chapter 2, IEEE Arithmetic Model, four rounding directions]{ref}