TorchLean API

FloatLib.Floats.Formats.DecimalInterchange.Conversion.Binary.ToProof

Decimal-to-binary conversion contracts #

Finite decimal inputs are evaluated as exact rationals, independently of their cohort. Nearest-even conversion refines binary rounded-real semantics, and nearest-away conversion has the integer-grid semantics proved in NearestAwayProof. The directed conversions inherit the binary kernels' extended-real enclosure bounds, which include overflow to infinity.

Exception theorems state the overflow and tininess predicates, including the distinction between exponent overflow and an inexact result at the largest finite value.

Signed natural quotient semantics agree with the exact rational input.

theorem FloatLib.Floats.Formats.DecimalInterchange.Conversion.toBinary_eq_of_magnitude_eq (fmt : BinaryInterchange.FloatFormat) (hfmt : fmt.isIEEE = true) (mode : RoundingMode) (s : Bool) (c₁ c₂ : ℕ) (q₁ q₂ : ℤ) (h : ↑c₁ * 10 ^ q₁ = ↑c₂ * 10 ^ q₂) :
toBinary fmt hfmt mode (Datum.finite s c₁ q₁) = toBinary fmt hfmt mode (Datum.finite s c₂ q₂)

The source cohort affects neither the rounded binary value, its flags, nor its ternary value.

@[simp]

An infinity keeps its sign and raises no exception.

@[simp]
theorem FloatLib.Floats.Formats.DecimalInterchange.Conversion.toBinary_nan (fmt : BinaryInterchange.FloatFormat) (hfmt : fmt.isIEEE = true) (mode : RoundingMode) (s signaling : Bool) (payload : ℕ) :
toBinary fmt hfmt mode (Datum.nan s signaling payload) = { value := binaryNaN fmt s payload, status := { invalid := signaling }, ternary := Ordering.eq }

A signaling NaN raises invalid and a quiet NaN does not. Both deliver the quiet NaN of binaryNaN and raise no other flag.

@[simp]

Zero magnitude rounds to the binary zero of sign s in every mode.

Finite nearest-even rational conversion equals binary rounded-real semantics.

Nearest-even conversion of a finite decimal input is one binary rounding of its value, provided the delivered result is finite.

Nearest-away conversion of a finite decimal input with a finite result delivers its rounded dyadic on the destination grid, so the encoder adds no second rounding.

Upward rational conversion encloses the exact input, including an infinite result.

Downward rational conversion encloses the exact input, including an infinite result.

Conversion toward positive infinity is an extended-real upper bound.

Conversion toward negative infinity is an extended-real lower bound.

A positive decimal input rounded toward zero does not increase.

A negative decimal input rounded toward zero does not decrease.

@[simp]

A finite decimal input cannot raise invalid during numeric conversion.

@[simp]

Numeric conversion cannot raise division-by-zero.

The finite conversion path raises overflow exactly at the mode's rational boundary.

Inexact means exponent overflow or a changed exact rational value.

theorem FloatLib.Floats.Formats.DecimalInterchange.Conversion.toBinary_underflow_iff (fmt : BinaryInterchange.FloatFormat) (hfmt : fmt.isIEEE = true) (mode : RoundingMode) (s : Bool) (c : ℕ) (q : ℤ) :
(toBinary fmt hfmt mode (Datum.finite s c q)).status.underflow = true ↔ (toBinary fmt hfmt mode (Datum.finite s c q)).status.overflow = false ∧ binaryTiny fmt mode s (↑c * 10 ^ q) (toBinary fmt hfmt mode (Datum.finite s c q)).value = true ∧ (toBinary fmt hfmt mode (Datum.finite s c q)).status.inexact = true

Underflow is an inexact tiny result without exponent overflow. Tininess is measured after rounding to the destination precision with an unbounded exponent range.