TorchLean API

FloatLib.Floats.Formats.P3109.Projection.Rational.Runtime

Exact-rational P3109 projection #

Configured binary floats, posits, integer inputs, and exact finite arithmetic can all supply exact rational values. This module projects them into any valid P3109 descriptor, rounding from the numerator and denominator with no intermediate approximation.

The runtime follows the same P3109 projection order as dyadic projection:

  1. select the descriptor quantum;
  2. round the exact quotient according to the requested P3109 mode;
  3. apply the shared saturation rule;
  4. encode the resulting datum.

The dyadic entry point suits a caller that already has an exact binary value. Both paths share saturation, encoding, and descriptor logic.

@[inline]

Floor of (remainder / denominator) * 2^outputBits.

Instances For
    @[inline]

    Nearest-even integer to (remainder / denominator) * 2^outputBits.

    Instances For
      @[inline]
      def FloatLib.Floats.Formats.P3109.Format.Internal.roundRationalAwayWithParity (mode : RoundingMode) (negative lowerEven : Bool) (remainder denominator : ℕ) :

      Decide whether exact rational rounding selects the integer above the quotient floor.

      denominator is positive, as for every Rat. Passing it as its own argument lets the stochastic formulas follow P3109 Section 4.7.4 term by term.

      Instances For
        @[inline]
        def FloatLib.Floats.Formats.P3109.Format.Internal.roundRationalAway (format : Format) (mode : RoundingMode) (negative : Bool) (quantumExponent : ℤ) (lower remainder denominator : ℕ) :

        P3109 rational rounding uses the descriptor's code parity, including precision one.

        Instances For
          @[inline]

          Round one exact finite rational to the descriptor's P3109 precision.

          The selected quantum is max(floor(log2 |x|), 1 - B) - P + 1. Scaling by the opposite quantum turns the rounding decision into one natural-number quotient and remainder. The result is an exact dyadic datum on the P3109 precision grid.

          Instances For
            @[inline]

            Apply P3109 precision rounding to an exact-rational closed value.

            Instances For
              @[inline]

              Exact-rational P3109 result before representation encoding.

              Instances For
                @[inline]

                Project one exact-rational closed value and return its descriptor-width code.

                Instances For
                  @[inline]

                  Project an exact rational, infinity, or exceptional observation into a P3109 descriptor.

                  Finite values are rounded once from their exact numerator and denominator, in mode, before saturation applies. No intermediate binary or host floating-point format is involved.

                  Instances For
                    @[inline]

                    Round one exact rational into a P3109 descriptor, nearest-even with no saturation request by default, as in ExecFloat.P3109.ofRat (format := .binary8p4se) (1 / 3) (mode := .up).

                    Instances For