TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Algebraic.Rounding.Runtime

Exact comparison rounding for binary algebraic operations #

A comparison oracle orders a nonnegative real target against exact rational candidates. Two bounded searches locate its binade and a truncated significand with two extra bits. An exact comparison with the half-integer then supplies Lean's accuracy certificate. The final rounding discards that certificate once; no floating-point approximation of the target is needed.

The search bounds come from the complete descriptor. Custom biases and finite encodings use the descriptor-aware dyadic rounder with a representative of the same accuracy class.

@[inline]

Exact rational power of two, including negative exponents.

Instances For
    @[reducible, inline]

    Reuse the total bounded integer search shared by exact posit operations.

    Instances For
      @[inline]

      The lowest binade whose values can round to a nonzero encoding.

      Instances For
        @[inline]

        An exclusive upper bound above every finite magnitude.

        Instances For
          @[inline]

          Number of candidate exponent intervals.

          Instances For

            Locate the binade by exact comparisons with powers of two.

            Instances For
              @[inline]

              Keep two bits below the final normal or subnormal rounding position.

              Instances For

                A truncated positive magnitude and the exact location of its discarded fraction.

                • mantissa : ℕ

                  Integer part of the magnitude after scaling by 2 ^ (-exponent).

                • exponent : ℤ

                  Power of two represented by one unit of the mantissa.

                • Whether the discarded fraction is zero, below a half, a half, or above a half.

                Instances For

                  Integer part of a scaled magnitude, found by exact comparisons.

                  Instances For

                    Exact fractional classification after finding the integer part.

                    Instances For

                      Build a certificate with a search bounded by the descriptor's precision.

                      Instances For
                        @[inline]

                        A quarter-integer in the same accuracy class as a certificate's real mantissa.

                        Instances For
                          @[inline]

                          Round a certificate once. Its exponent must be no greater than the target exponent; the constructor above reserves two guard bits to ensure this throughout the finite search interval.

                          Instances For

                            Total nearest-even rounding of a signed magnitude given an exact comparison oracle.

                            The oracle's contract is comparison with a nonnegative real. At half the least subnormal, ties select signed zero. The upper cutoff uses the descriptor's overflow policy; values just below it still pass through the significand rounder, which handles overflow caused by carry.

                            Instances For
                              @[inline]

                              Single-round evaluation of a nonnegative rational root.

                              Instances For