TorchLean API

FloatLib.Floats.Formats.DecimalInterchange.Conversion.Integer.Rounding

Integer-grid rounding guarantees #

The rounded integer fixes every exact integer, satisfies the directed bounds, and lies within half a unit in either nearest mode. The midpoint theorems specify the tie choice, which an error bound alone would not determine.

All five directions change a rational by strictly less than one integer unit.

The two nearest modes have at most one-half unit of error.

@[simp]

Exact integers are fixed in every direction, including either sign and zero.

theorem FloatLib.Floats.Formats.DecimalInterchange.Conversion.Integer.roundInteger_nearestEven_midpoint (negative : Bool) (n : ) :
roundInteger RoundingMode.nearestEven (if negative = true then -(n + 1 / 2) else n + 1 / 2) = have rounded := if n % 2 = 1 then ↑(n + 1) else n; if negative = true then -rounded else rounded

The sign is applied after the even adjacent magnitude has been selected.