Integer Rounding Functions #
This module collects the integer-valued rounding primitives (round0,
roundinf, roundup, rounddown, roundnearest) used to round a rational to a
mantissa, together with their basic correctness properties such as round-to-even
behaviour on half-integers.
An integer-valued rounding rule taking a sign bit and a rational mantissa.
Equations
- IntRounder = (Bool → ℚ → ℕ)
Instances For
Round to nearest as an IntRounder: ties to even, ignoring the sign.
Equations
- roundnearest s q = if s = true then (roundNearInt q).natAbs else (roundNearInt q).natAbs
Instances For
roundnearest ignores its sign argument.
The set of rationals whose ceiling is z, namely (z - 1, z].
Equations
- ceilInterval z = Set.Ioc (↑z - 1) ↑z
Instances For
A positivity extension proving 0 ≤ roundNearInt q from 0 ≤ q.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A rounding rule is valid if it is monotone on nonnegative inputs and is a
left inverse of the cast ℕ → ℚ (so it fixes integer mantissas).
The rounder is monotone in the mantissa on nonnegative inputs.
- leftInverse (s : Bool) : Function.LeftInverse (f s) Nat.cast
The rounder fixes integer mantissas: it left-inverts the cast
ℕ → ℚ.
Instances
The rounder obtained by flipping the sign bit, used to relate rounding of
q and -q.