TorchLean API

FloatLib.Floats.Formats.DecimalInterchange.Integral.Proof

Integral result, preferred quantum, and status guarantees #

When the format's maximum quantum is nonnegative, every valid finite input produces a finite integer at the specified preferred quantum, with no intermediate precision loss or range exception. This includes all three standard presets. The general invalid characterization also covers custom layouts with a negative maximum quantum.

The coefficient of a rounded integral value never exceeds the input coefficient.

theorem FloatLib.Floats.Formats.DecimalInterchange.Arithmetic.roundToIntegralExact_finite (f : Format) (mode : RoundingMode) (s : Bool) (c : ) (q : ) (hv : Datum.Valid f (Datum.finite s c q)) (hzero : 0 f.maxQuantum) :
roundToIntegralExact f mode (Datum.finite s c q) = { value := Datum.finite s (mode.roundAt s (c * 10 ^ q) (max q 0)) (max q 0), status := { inexact := decide ((mode.roundAt s (c * 10 ^ q) (max q 0)) * 10 ^ max q 0 c * 10 ^ q) } }

The successful output explicitly retains the sign and preferred quantum, including zero.

For a valid finite input, invalid occurs exactly when the preferred integral quantum cannot be represented. The coefficient bound never causes this failure.

A valid finite input rounds to an integer when the maximum quantum is nonnegative.

A valid finite input raises no range, domain, or divide-by-zero exception when the maximum quantum is nonnegative.

@[simp]

Explicit-direction integral rounding suppresses inexact, including for a nonintegral input.

Exact integral rounding signals inexact precisely for a numerical change.

Already nonnegative quantum exponents are preserved, including trailing coefficient zeros.

Both nearest integral modes differ from the input by at most one half, independent of its cohort.

@[simp]

The two integral variants have exactly the same numerical datum.