TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.DirectedSemantics.Rational.Conversion

Exact rational conversion for directed Model rounding #

Model.ofRat fmt q rounds a normalized mathlib Rat once into any Model fmt, to nearest with ties to even. (mode := .up) selects another direction and (status := true) adds the IEEE exception flags and the ternary value. For conventional IEEE formats, directed overflow returns either a signed infinity or the largest finite value of the same sign, according to the rounding direction. The conversion theorems establish the extended-real lower and upper bounds and non-NaN results in both directions.

@[macro_inline]

Round an exact rational once into fmt, in the direction mode (nearest-even by default). With status := true the result is the IEEEOutcome carrying the exception flags and the ternary value of that rounding.

Instances For
    @[simp]

    Rounding a rational with status := true delivers the value of the same rounding.

    Downward conversion of an exact rational is an extended-real lower bound.

    Upward conversion of an exact rational is an extended-real upper bound, including zero, subnormal rounding, and overflow to positive infinity.

    Downward conversion of a normalized rational never produces NaN.

    Upward conversion of a normalized rational never produces NaN.