TorchLean API

FloatLib.Floats.Formats.P3109.Conversion.Runtime

Conversion into P3109 formats #

P3109 destinations use Rat as their canonical exact scalar domain. This lets integers, exact dyadics, configured binary floats, configured posits, and other rationally decoded sources use the ordinary convert, cast, and destination-driven mixed-operation APIs without first passing through a host float.

The conversion context is exactly ProjectionPolicy: the P3109 rounding mode and saturation mode are not duplicated in a second policy type. Every policy produces a P3109 datum, so conversion returns success for finite, infinite, and exceptional observations. Changes to an input infinity or exceptional observation are reported through mappedSpecial; endpoint clamping is reported through saturated.

@[inline]

Decode a P3109 value in the common exact-rational scalar domain.

Instances For
    @[inline]

    Whether an exact rational lies strictly outside the closed interval [minFinite, maxFinite].

    This is a property of the exact input alone. It is not the overflow indicator: an input slightly above maxFinite that rounds back to maxFinite satisfies this predicate but does not overflow.

    Instances For
      @[inline]

      Whether the precision-rounded value of an exact rational lies strictly outside [minFinite, maxFinite].

      Rounding is roundFiniteRatToPrecision in the requested mode, before any saturation. This is the after-rounding range condition of P3109 §4.7.3: an input that rounds to maxFinite is in range even when its exact magnitude exceeds maxFinite. Because the endpoints lie on the precision grid, no rounding mode moves an in-range input past them, so this condition is stronger than exceedsFiniteRange. The theorem roundedExceedsFiniteRange_implies_exceedsFiniteRange in Conversion.Range proves this implication for every mode and every supplied stochastic word.

      Instances For
        @[inline]

        Whether a nonzero exact magnitude is strictly smaller than the least positive finite P3109 datum.

        The comparison is sign-independent and scales by binary position before cross multiplication, so large exponent ranges do not create an enormous temporary rational. This threshold is the least positive datum (the smallest subnormal when the descriptor has subnormals), not the least normal datum used by IEEE 754 tininess.

        Instances For
          @[inline]

          Whether a projected datum is one of the descriptor's finite endpoints.

          Instances For
            @[inline]

            Whether projection deliberately changed a source special-value class or infinity sign.

            Instances For
              @[inline]

              Whether projection changes the exact rational input or produces a nonfinite datum.

              Instances For
                @[inline]

                Conversion indicators for one completed P3109 projection.

                The report defines no status flags, so these are FloatLib's conversion indicators:

                • overflow is roundedExceedsFiniteRange: the value rounded to the descriptor's precision in the requested mode lies outside [minFinite, maxFinite]. It does not depend on the saturation mode, and an input that rounds to an endpoint does not overflow (Section 4.7.3, NOTE 1).
                • underflow is belowMinPositive: a nonzero exact input strictly smaller in magnitude than the least positive datum. A subnormal-range input that is at least the least positive datum does not raise it, so this is narrower than IEEE 754 tininess.
                • saturated is raised only when saturation changed the rounding result and the delivered datum is a finite endpoint.
                Instances For
                  @[inline]

                  Quantize one complete exact-rational observation according to its P3109 projection policy.

                  Instances For

                    Conversion preserves the selected word and status and denotes the round-then-saturate datum.

                    SameDatum compares finite values numerically and identifies NaN payloads. The word equality is retained separately so that this semantic clause does not discard complete output information.

                    Instances For
                      @[instance_reducible, instance 2000]

                      P3109 decoding selects the common exact-rational scalar domain.

                      The elevated priority refines the carrier's generic codebook decoder, whose finite domain is Dyadic. Importing the generic codebook API together with P3109 therefore still leaves one canonical source domain for ordinary scalar conversion.