TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Operations.Compare.Runtime

Executable binary comparisons #

Comparison first handles NaNs and signed infinities, then compares finite values through their exact dyadic denotations. This gives every FloatFormat one numerical order without assuming a particular storage width or relying on host floating-point comparison.

NaNs are unordered. The minimum and maximum operations apply their NaN-selection and signed-zero rules around the same comparator. Both the deprecated IEEE 754-2008 minNum/maxNum and the IEEE 754-2019 minimumNumber/maximumNumber operations are provided, and they differ only in how a signaling NaN operand is treated.

Numerical ordering once both operands are known not to be NaNs.

Infinity is ordered by sign. Every remaining bit pattern is finite, so comparison uses the exact dyadics extracted from those classification proofs.

Instances For

    IEEE numerical comparison: none if either operand is a NaN (unordered), otherwise the ordering.

    Infinities are ordered first by sign, and finite values are compared through cmpDyadic.

    Instances For

      Strict IEEE order, compare x y = some .lt. It fails when either operand is a NaN.

      Instances For

        Weak IEEE order, compare x y is some .lt or some .eq. It fails for a NaN operand.

        Instances For
          @[instance_reducible]

          le is decided by the executable comparison.

          IEEE minimum, with NaNs selected by chooseNaN2 and minimum(-0,+0) = -0.

          Instances For

            IEEE maximum, with NaNs selected by chooseNaN2 and maximum(-0,+0) = +0.

            Instances For

              IEEE 754-2008 minNum, deprecated by IEEE 754-2019 in favor of minimumNumber.

              A signaling NaN takes priority and propagates as a quiet NaN. Otherwise, a lone quiet NaN is ignored, two quiet NaNs select the left operand after quieting, and two numbers use minimum, including its minNum(-0, +0) = -0 rule.

              Instances For

                IEEE 754-2008 maxNum, deprecated by IEEE 754-2019 in favor of maximumNumber.

                A signaling NaN takes priority and propagates as a quiet NaN. Otherwise, a lone quiet NaN is ignored, two quiet NaNs select the left operand after quieting, and two numbers use maximum, including its maxNum(-0, +0) = +0 rule.

                Instances For
                  @[inline]

                  Quiet NaN delivered when both operands of minimumNumber or maximumNumber are NaNs.

                  The signaling operand is preferred, then the left operand, matching chooseNaN2.

                  Instances For

                    IEEE 754-2019 §9.6 minimumNumber, the kernel of Model.minimumNumber x y.

                    If exactly one operand is a NaN, quiet or signaling, the other operand is returned, so a signaling NaN is not propagated. When both operands are NaNs the result is a quiet NaN chosen by bothNaNNumber. On two numbers this is minimum, so minimumNumber(-0, +0) = -0. The invalid signal owed to a signaling operand is reported by Model.minimumNumber x y (status := true) in Operations.Runtime, since the value alone carries no status.

                    Instances For

                      IEEE 754-2019 §9.6 maximumNumber, the kernel of Model.maximumNumber x y.

                      If exactly one operand is a NaN, quiet or signaling, the other operand is returned, so a signaling NaN is not propagated. When both operands are NaNs the result is a quiet NaN chosen by bothNaNNumber. On two numbers this is maximum, so maximumNumber(-0, +0) = +0. The invalid signal owed to a signaling operand is reported by Model.maximumNumber x y (status := true) in Operations.Runtime.

                      Instances For