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.
theorem
FloatLib.Floats.Formats.DecimalInterchange.Conversion.Integer.cast_roundInteger
(mode : RoundingMode)
(value : ℚ)
:
theorem
FloatLib.Floats.Formats.DecimalInterchange.Conversion.Integer.roundInteger_error_eq
(mode : RoundingMode)
(value : ℚ)
:
theorem
FloatLib.Floats.Formats.DecimalInterchange.Conversion.Integer.roundInteger_error_lt_one
(mode : RoundingMode)
(value : ℚ)
:
All five directions change a rational by strictly less than one integer unit.
theorem
FloatLib.Floats.Formats.DecimalInterchange.Conversion.Integer.roundInteger_error_le_half
(mode : RoundingMode)
(hm : mode = RoundingMode.nearestEven ∨ mode = RoundingMode.nearestAway)
(value : ℚ)
:
The two nearest modes have at most one-half unit of error.
theorem
FloatLib.Floats.Formats.DecimalInterchange.Conversion.Integer.roundInteger_of_nonneg
(mode : RoundingMode)
(value : ℚ)
(h : 0 ≤ value)
:
theorem
FloatLib.Floats.Formats.DecimalInterchange.Conversion.Integer.roundInteger_of_neg
(mode : RoundingMode)
(value : ℚ)
(h : value < 0)
:
@[simp]
theorem
FloatLib.Floats.Formats.DecimalInterchange.Conversion.Integer.roundInteger_intCast
(mode : RoundingMode)
(value : ℤ)
:
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 : ℕ)
:
The sign is applied after the even adjacent magnitude has been selected.