TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Conversion.Text.DecimalFormattingProof

Correctness of fixed and scientific decimal output #

The notation scanner recovers the decimal value selected by rounding. Fixed output has at most half a decimal place of nearest-even error; scientific output inherits the significant-digit bound. Neither decimal-point placement nor exponent notation introduces additional rounding.

Nearest-even rounding on any decimal grid changes the value by at most half a grid unit.

@[simp]

Either decimal notation denotes the original decimal, without an extra rounding step.

The characters denote precisely the value selected by decimal rounding.

@[simp]

Choosing notation and precision preserves the sign, including when the result is zero.

Inexact is set exactly when the decimal rounding changes the numerical value.

Decimal text has unbounded exponents; output rounding can raise only inexact.

A finite model's output denotes its exact dyadic value rounded to the selected decimal grid.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.formatFixed_nearestEven_error {fmt : FloatFormat} (value : Model fmt) (d : Numerics.Dyadic) (h : value.toDyadic? = some d) (places : ) :
∃ (result : ), Numerics.DecimalText.parse (value.formatFixed places) = some result |result - d.toRat| 10 ^ (-places) / 2

The actual fixed-point string has at most half a last-place unit of nearest-even error.

The actual scientific string inherits the nearest-even significant-digit error bound.