TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Conversion.Text.PrecisionProof

Requested-precision guarantees for binary character output #

The integer rounder is independent of the external radix and the binary descriptor. The shared radix laws then give coefficient bounds, fixed points and the numerical interpretation of the emitted characters.

@[simp]

Every output rounding direction fixes a nonnegative integer.

Nearest-even integer output has error at most one half on a nonnegative magnitude.

Nearest-away integer output of a nonnegative magnitude exceeds a natural bound exactly when the magnitude reaches the bound plus one half.

An external magnitude rounder never falls below floor.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.roundTextMagnitude_le_nat (mode : IEEERoundingMode) (negative : Bool) (x : ℚ) (n : ℕ) (hx : 0 ≤ x) (hn : x ≤ ↑n) :
roundTextMagnitude mode negative x ≤ n

An integer upper bound on a magnitude also bounds its rounded coefficient.

Requested decimal output has exactly the requested digit count for nonzero inputs.

Enough decimal digits preserve the exact value, for any binary descriptor and direction.

At a halfway integer, the common output rounder selects the even neighbor.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.significantMagnitude_nearest_error (radix : ℕ) (hradix : 1 < radix) (negative : Bool) (coefficient : ℕ) (quantum : ℤ) (digits : ℕ+) :
|↑(Numerics.RadixText.significant radix (roundTextMagnitude IEEERoundingMode.nearest) negative coefficient quantum digits).1 * ↑radix ^ (Numerics.RadixText.significant radix (roundTextMagnitude IEEERoundingMode.nearest) negative coefficient quantum digits).2 - ↑coefficient * ↑radix ^ quantum| ≤ ↑radix ^ Numerics.RadixText.significantQuantum radix coefficient quantum digits / 2

The same half-grid error guarantee holds in any external radix greater than one.

Nearest-even hexadecimal output has at most half a requested hexadecimal grid unit of error.

Requested hexadecimal output has exactly the requested digit count for nonzero input.

Decimal output rounded toward positive infinity is at least the exact input.

Decimal output rounded toward negative infinity is at most the exact input.

Hexadecimal output toward positive infinity is at least the exact input.

Hexadecimal output toward negative infinity is at most the exact input.