TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Conversion.Text.Roundtrip

Exact binary character round trips #

The string scanner recovers the exact coefficient and exponent. For conventional IEEE descriptors, finite hexadecimal output round-trips in every supported rounding mode, and finite exact decimal output and the shortest display round-trip under nearest-even input. All results include signed zero.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.TextParser.run_of_readText (fmt : FloatFormat) (mode : IEEERoundingMode) (text : String) (value : TextValue) (hread : readText text = some value) :
run fmt mode text = convertText fmt mode value

Successfully scanned text passes unchanged to the destination conversion.

@[simp]

The shared binary scanner recognizes every exact decimal spelling.

@[simp]

The shared binary scanner recognizes every exact hexadecimal spelling.

Hexadecimal text restores a finite IEEE word in every supported rounding direction.

The rational operands used by decimal conversion denote the complete decimal value.

Decimal conversion rounds the complete exact input once, including inexact text and zero.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.toReal_parse_decimal_nearest {fmt : FloatFormat} (hfmt : fmt.isIEEE = true) (text : String) (value : Numerics.DecimalText.Decimal) (result : Model fmt) (hread : readText text = some (TextValue.decimal value)) (hparse : parse fmt text = Except.ok result) (hfinite : result.isFinite = true) :
result.toReal = roundAt fmt ↑value.toRat

Successfully parsed decimal text has the nearest-even real value of its exact decimal datum. The input may be inexact for the destination. Only a nonfinite delivered value is excluded.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.convertDecimalText_eq_of_nonzero {fmt : FloatFormat} (hfmt : fmt.isIEEE = true) (value : Model fmt) (hfinite : value.isFinite = true) (hzero : value.toReal ≠ 0) (textValue : Numerics.DecimalText.Decimal) (hexact : ↑textValue.toRat = value.toReal) :

Decimal conversion of an exact finite nonzero value restores its complete IEEE word.

Exact decimal output restores every nonzero finite IEEE word under nearest-even input.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.convertDecimalText_zero {fmt : FloatFormat} (hfmt : fmt.isIEEE = true) (value : Model fmt) (d : Numerics.Dyadic) (hd : value.toDyadic? = some d) (hm : d.significand = 0) :
value.toDyadic? = some { negative := value.signBit, significand := 0, exponent := 0 } ∧ (convertDecimalText fmt IEEERoundingMode.nearest { negative := value.signBit, significand := 0, exponent := 0 }).value = value

A zero of an IEEE format, with its sign, is the nearest-even conversion of signed zero text.

Exact decimal output restores every finite IEEE word, including either signed zero.

Decimal conversion depends only on the sign and the value of the decimal record.

The displayed characters read back as a record with the sign and value of the displayed one.

The displayed record of a finite IEEE word converts back to the word in nearest-even.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.parse_format_of_isFinite {fmt : FloatFormat} (hfmt : fmt.isIEEE = true) (value : Model fmt) (hfinite : value.isFinite = true) :
parse fmt value.format = Except.ok value

The display of every finite IEEE word reads back as the same word.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.parse_toString_of_isFinite {fmt : FloatFormat} (hfmt : fmt.isIEEE = true) (value : Model fmt) (hfinite : value.isFinite = true) :
parse fmt (toString value) = Except.ok value

toString of every finite IEEE word reads back as the same word.