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; nearest-away conversion has the exact integer-grid semantics proved in NearestAwayProof. The directed conversions inherit the binary kernels' extended-real enclosure bounds, which include overflow to infinity.

Exception theorems expose the exact 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 nor its flags.

@[simp]

Infinities preserve their sign and raise 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 } }

A signaling NaN raises invalid; a quiet NaN does not. Both use the documented quiet payload-selection policy and raise no other flag.

@[simp]

Zero magnitude rounds to the source-signed binary zero in every mode.

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

Nearest-even conversion of a finite decimal input has one binary rounding. The observable finiteness condition excludes an infinite delivered result.

Nearest-away conversion of a finite decimal input equals its exact rounded dyadic on the destination grid; the encoder contributes 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.