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 directly into any valid P3109 descriptor, rounding from the numerator and denominator without an 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 directly.

The dyadic entry point remains useful when the caller already owns 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 for every Rat. Keeping it explicit makes the stochastic formulas match P3109 Section 4.7.4 directly.

      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. No intermediate binary or host floating-point format is involved.

                  Instances For
                    @[inline]

                    Project one finite exact rational into a P3109 descriptor.

                    Instances For