TorchLean API

FloatLib.Floats.Formats.P3109.Projection.Runtime

P3109 projection #

P3109 projection has three distinct steps:

  1. round finite dyadics to the descriptor's precision, preserve infinities, and map exceptions to NaN;
  2. apply the selected saturation rule at the descriptor's finite endpoints;
  3. encode the resulting datum.

This module follows that order directly. All integer widths, exponent bounds, and special codes come from Format; there are no named-width branches or host floating-point conversions.

The stochastic modes receive a caller-supplied BitVec, whose width enforces the random-word range.

Reference #

Exact random bits supplied to one P3109 stochastic-rounding decision.

  • width :

    Number of random bits (N in the report).

  • bits : BitVec self.width

    Unsigned random integer, intrinsically restricted to 0 ≤ R < 2^N.

Instances For
    @[inline]

    Construct a supplied random word from the low width bits of a natural number.

    Instances For
      @[inline]

      Read the supplied random bits as an unsigned natural number.

      Instances For

        Rounding modes defined by P3109 Section 4.7.4.

        Instances For

          Saturation modes defined by P3109 Section 4.7.5.

          Instances For

            Complete policy used by one P3109 projection.

            • rounding : RoundingMode

              Rule used when precision rounding discards nonzero low bits.

            • saturation : SaturationMode

              Rule used after rounding produces a value outside the target datum set.

            Instances For

              FloatLib default projection: nearest-even rounding and no finite saturation request.

              Instances For

                Nearest-even projection clamped to the finite range.

                Instances For
                  @[inline]

                  Largest finite positive code point for this descriptor.

                  Instances For
                    @[inline]

                    Exact largest finite value in this descriptor.

                    Instances For
                      @[inline]

                      Exact smallest finite value in this descriptor.

                      Instances For
                        @[inline]
                        def FloatLib.Floats.Formats.P3109.Format.lowerCodeIsEven (format : Format) (quantumExponent : ) (lowerSignificand : ) :

                        Whether the lower candidate has an even P3109 code at a rounding boundary.

                        For P > 1, code parity is ordinary significand parity. The P = 1 branch is the special rule from Section 4.7.4: zero is even, and a nonzero code is even exactly when Q + B is even.

                        Instances For
                          @[inline]

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

                          Instances For
                            @[inline]

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

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

                              Decide whether precision rounding selects the integer above the floor candidate.

                              Instances For
                                @[inline]

                                Round one exact finite dyadic to P3109 precision before saturation.

                                The quantum is max(floor(log2 |X|), 1 - B) - P + 1, so the same implementation handles normals, subnormals, P = 1, and arbitrary descriptor widths.

                                Instances For
                                  @[inline]

                                  Apply P3109 precision rounding while preserving infinities and mapping exceptions to NaN.

                                  Instances For
                                    @[inline]

                                    Saturate a rounded value below the finite range.

                                    Instances For
                                      @[inline]

                                      Saturate a rounded value above the finite range.

                                      Instances For
                                        @[inline]

                                        Apply P3109 Section 4.7.5 to a value that has already been rounded to precision.

                                        Instances For
                                          @[inline]

                                          Mathematical result of P3109 projection before representation encoding.

                                          Precision rounding is followed by saturation. The result gives the datum meaning before encoding.

                                          Instances For
                                            @[inline]

                                            Encode a positive finite datum.

                                            The caller supplies a value already rounded to precision and inside the finite range. This is the integer form of Section 4.7.6; it does not enumerate the codebook.

                                            Instances For
                                              @[inline]

                                              Encode a value known to be in this descriptor's datum set.

                                              Instances For

                                                P3109 equality of datum meanings.

                                                Finite values are equal numerically, infinity signs must match, and every NaN payload denotes the format's single NaN datum. Other exceptional categories are not P3109 datums.

                                                Instances For
                                                  @[inline]

                                                  Executable equality of P3109 datum meanings.

                                                  Finite dyadics are compared numerically, so harmless differences in significand normalization do not make a representable value fail the checked encoder. P3109 has one NaN, so its optional payload is not semantically observable here.

                                                  Instances For
                                                    @[inline]

                                                    Encode a value only when it belongs to this descriptor's datum set.

                                                    Unlike projection, this operation performs no rounding or saturation. It computes the direct P3109 code, decodes it, and accepts the result only when the numerical datum is unchanged.

                                                    Instances For
                                                      @[inline]

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

                                                      Instances For
                                                        @[inline]

                                                        Project an exact finite, infinite, or NaN value into a P3109 descriptor.

                                                        The operation rounds once to P3109 precision, applies saturation, and encodes the result directly. It never routes through IEEE 754 or a host float.

                                                        Instances For
                                                          @[inline]

                                                          Project one exact finite dyadic into a P3109 descriptor.

                                                          Instances For
                                                            @[inline]

                                                            Encode an already representable P3109 datum without rounding it.

                                                            Instances For