TorchLean API

FloatLib.Floats.ExecFloat.Backends.Word.Full.Sqrt.Runtime

Native binary64 square-root runtime #

Positive finite inputs are scaled to a 105- or 106-bit radicand held in two UInt64 limbs. A 53-step restoring square-root loop computes the floor root and remainder using native words. The remainder classifies the nearest-even result directly, after which the binary64 exponent and fraction are packed without constructing a generic unpacked-float model.

Correctness proofs and the Nat.sqrt model are isolated in Sqrt.Proof.

@[inline]

Shift a binary64 significand into two limbs; callers supply a positive shift below 128 and a result that fits in 128 bits.

Instances For
    @[inline]

    Read a base-four digit of a two-limb radicand, for an index below 64.

    Instances For
      @[inline]

      Consume one base-four digit in the restoring square-root recurrence.

      For the binary64 radicands constructed above, 53 iterations produce a 53-bit floor root. The remainder and trial divisor remain below one native word.

      Instances For
        @[inline]

        Consume a requested number of radicand digits from most significant to least significant.

        Instances For
          @[inline]

          Compute the floor root and exact remainder of a binary64-sized scaled radicand.

          Instances For
            @[inline]

            Direct positive-finite binary64 square root.

            For a nonzero significand below 2^53 and a scale at most 2045, the input value is mantissa * 2^(scale - 1074), with subtraction in the exponent interpreted in Int. Parity chooses a 105- or 106-bit integer radicand. Its square root cannot be a half-integer, so remainder ≤ root is precisely the round-down condition.

            Instances For
              @[inline]

              Decode binary64 fields and run the bounded positive-finite square-root kernel.

              Instances For
                @[inline]

                Native binary64 square root, including IEEE exceptional-value behavior.

                Instances For