TorchLean API

FloatLib.Floats.Formats.P3109.Arithmetic.Sqrt.Runtime

P3109 square-root rounding by exact square comparisons #

For a nonnegative rational radicand, the floor candidate is sqrt (numerator / denominator) computed in natural numbers. Rounding compares the radicand with the square of an exact rational threshold. This decides rounding of the square root even when it is irrational.

Stochastic A and B select the upper candidate at their supplied random threshold. Stochastic C uses the half-integer threshold of its nearest-even integer rounding, including its tie parity. The random word is an explicit input, as in §4.7.4 of the P3109 4.0.3 working-group report.

Square root, reciprocal square root, and hypotenuse follow §§4.10.8 and 4.10.14 of that unapproved report. Each evaluates its exact radicand before the one rounding and saturation step.

@[inline]

Floor of the nonnegative square root of numerator / denominator.

Instances For
    @[inline]
    def FloatLib.Floats.Formats.P3109.Arithmetic.compareSqrt (numerator denominator scale threshold : ) :

    Compare sqrt (numerator / denominator) with threshold / scale by squaring. The denominator and threshold scale are positive at every arithmetic call site.

    Instances For
      def FloatLib.Floats.Formats.P3109.Arithmetic.sqrtRoundDecision (format : Format) (mode : RoundingMode) (quantum : ) (lower : ) (exact : Bool) (compareThreshold : Ordering) :

      Select the upper candidate from exact threshold comparisons.

      For stochastic A and B the threshold is the first fraction whose scaled floor reaches the required integer. For C it is the midpoint below that integer, with the integer's tie parity. The comparison argument permits the executable square comparisons and real semantics to share these policy rules.

      Instances For
        def FloatLib.Floats.Formats.P3109.Arithmetic.sqrtRoundAway (format : Format) (mode : RoundingMode) (quantum : ) (numerator denominator lower : ) :

        The executable square-root boundary test for one report rounding mode.

        Instances For
          def FloatLib.Floats.Formats.P3109.Arithmetic.sqrtQuantum (format : Format) (numerator denominator : ) :

          The report's quantum for the square root of a positive rational.

          Instances For

            Round the exact nonnegative square root to the descriptor's precision.

            The integer division of the radicand's binary exponent by two is floor division, including negative exponents. The scaled numerator and denominator represent the square of the significand, so the scaling exponent is -2 * quantum.

            Square-root callers establish that the radicand is nonnegative. On an arbitrary rational this precision helper rounds the square root of its absolute value.

            Instances For

              Square root in the closed domain, with precision rounding before saturation.

              Instances For

                Apply the report saturation policy after square-root precision rounding.

                Instances For

                  Encode the already rounded and saturated square-root datum.

                  Instances For

                    Exact radicand for reciprocal square root, retaining its distinct nonpositive domain.

                    Instances For

                      Exact sum of squares for hypotenuse; either NaN takes precedence over infinity.

                      Instances For
                        @[inline]

                        Project the exact square root of a closed rational datum.

                        Instances For
                          @[inline]

                          Square root into an independent destination; negative inputs produce NaN.

                          Instances For
                            @[inline]

                            Reciprocal square root with one final projection; nonpositive finite inputs produce NaN.

                            Instances For
                              @[inline]
                              def FloatLib.Floats.ExecFloat.P3109.hypotTo {leftFormat rightFormat : Formats.P3109.Format} (destination : Formats.P3109.Format) (policy : Formats.P3109.ProjectionPolicy) (left : P3109 leftFormat) (right : P3109 rightFormat) :
                              P3109 destination

                              Hypotenuse from the exact sum of squares, with no intermediate overflow or rounding.

                              Instances For
                                @[inline]

                                Same-format square root, rounding the exact real value.

                                Instances For
                                  @[inline]

                                  Same-format reciprocal square root, rounding the exact real value.

                                  Instances For
                                    @[inline]

                                    Same-format hypotenuse with one final projection of the exact norm.

                                    Instances For