Exact integer-valued posit functions #
Integer rounding does not introduce a second numerical rounding error. An integral input is already representable. For a nonintegral input, the tapered fraction budget suffices to encode both neighboring integers, including a ceiling at the next power of two. The argument uses field-layout semantics and applies to every descriptor width.
theorem
FloatLib.Floats.Formats.Posit.Model.exists_toRat?_integer_neighbor
{format : Format}
(value : Model format)
{q : ℚ}
(hvalue : value.toRat? = some q)
(n : ℤ)
(hlower : q.floor ≤ n)
(hupper : n ≤ q.ceil)
:
Every integer between the exact floor and ceiling of a finite posit is representable. This includes both endpoints and has no precision or magnitude precondition.
@[simp]
theorem
FloatLib.Floats.Formats.Posit.Model.toRat?_nearestInt
{format : Format}
(value : Model format)
:
Exact nearest-even semantics also accounts for the NaR input.
theorem
FloatLib.Floats.Formats.Posit.Model.nearestInt_spec
{format : Format}
(value : Model format)
{q : ℚ}
(hvalue : value.toRat? = some q)
:
The returned integer minimizes distance among all integers, lies within half a unit, and is even whenever that bound is attained. These properties describe the delivered posit.