TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Status.Runtime

IEEE exception status for format-parameterized Model #

The value operations remain pure and explicit about their rounding mode. This module pairs those values with the five IEEE exception indicators. Tininess is detected after rounding, and underflow is raised exactly when a tiny result is inexact.

Overflow is classified from the precision-rounded result with an unbounded exponent range, as in IEEE 754-2019 §7.4 and the GNU MPFR manual's exception definition: https://doi.org/10.1109/IEEESTD.2019.8766229 and https://www.mpfr.org/mpfr-current/mpfr.html#Exceptions.

@[reducible, inline]

The shared IEEE exception indicators, also used by decimal arithmetic.

Instances For

    A format-parameterized executable value paired with its IEEE exception status.

    • value : Model fmt

      Delivered floating-point result.

    • status : IEEEStatus

      Exception indicators raised while computing value.

    Instances For
      @[inline]

      Pair a value with either the invalid-operation flag or a clear status.

      Exceptional arithmetic paths share this constructor so the value and the Boolean invalid condition remain visible without duplicating conditional record construction.

      Instances For
        @[inline]

        Whether a finite rounded result is zero or subnormal.

        Instances For

          Exact positive value of the smallest normal number in fmt.

          Instances For

            Largest positive number below minNormalDyadic fmt on the format's precision grid with an unbounded exponent range. Its distance from the smallest normal is half one subnormal step.

            Instances For

              Positive boundary used by after-rounding tininess detection.

              Tininess after rounding is determined by first rounding to the destination precision with an unbounded exponent range. Immediately below the smallest normal value that unbounded grid has half the subnormal spacing, so its midpoint is one quarter of a subnormal step below minNormal. The midpoint itself rounds to the even minNormal significand and is not tiny.

              Instances For
                @[inline]

                Whether a directed mode rounds a result with this sign away from zero.

                Instances For

                  Whether a dyadic result is tiny after rounding to the destination precision with an unbounded exponent range.

                  Most tiny results are visible directly as zero or subnormal encodings. A result delivered as minNormal needs a mode-sensitive boundary:

                  • nearest-even uses the midpoint between minNormal and its unbounded-grid predecessor;
                  • rounding away from zero is tiny through that predecessor;
                  • rounding toward zero is tiny for every magnitude strictly below minNormal.
                  Instances For

                    Exact positive dyadic value of the largest finite number in fmt.

                    Instances For

                      Whether an exact dyadic magnitude exceeds the finite range of fmt.

                      Instances For

                        Positive midpoint between the largest finite value and the next magnitude on the same binary grid.

                        Nearest-even overflow is decided at this boundary. The midpoint itself overflows exactly when the largest finite significand is odd, because the conceptual next significand is then even.

                        Instances For

                          First grid magnitude beyond the largest finite value.

                          Instances For
                            @[inline]

                            Whether the largest finite significand is odd.

                            Instances For

                              Whether nearest-even rounding of an exact dyadic magnitude signals overflow.

                              Instances For

                                Whether truncating an exact dyadic magnitude still exceeds the finite range.

                                Instances For

                                  Whether rounding an exact dyadic signals overflow.

                                  Nearest-even uses the top finite midpoint. A directed mode that increases the magnitude overflows above maxFinite; a mode that decreases the magnitude overflows only at overflowLimit. For conventional IEEE encodings, that limit starts the next binade. For encodings that reserve a terminal fraction pattern, it can lie within the same binade.

                                  Instances For

                                    Classify rounding an exact dyadic to rounded under mode.

                                    Finite results use the proof-guided exact decoder. An exceptional rounded argument is classified explicitly as overflow or invalid; it is never treated as a clear status.

                                    Instances For

                                      Exact equality between (numerator / denominator) * 2^exponent and a signed dyadic.

                                      Instances For

                                        Whether a positive scaled rational magnitude exceeds the finite range of fmt.

                                        Instances For

                                          Whether a positive rational magnitude exceeds the finite range of fmt.

                                          Instances For

                                            Whether nearest-even rounding of a positive scaled rational signals overflow.

                                            Instances For

                                              Whether truncating a scaled rational magnitude still exceeds the finite range.

                                              Instances For

                                                Whether rounding an exact signed scaled rational signals overflow.

                                                The sign determines whether a directed mode increases or decreases magnitude. Magnitude-increasing rounding overflows above maxFinite; truncating rounding uses overflowLimit.

                                                Instances For

                                                  Whether rounding an exact rational signals overflow.

                                                  Instances For
                                                    def FloatLib.Floats.Formats.BinaryInterchange.Model.rationalIsTinyAfterRoundingScaled (fmt : FloatFormat) (mode : IEEERoundingMode) (sign : Bool) (numerator denominator : ) (exponent : ) (rounded : Model fmt) :

                                                    Whether a scaled rational result is tiny after rounding to the destination precision with an unbounded exponent range.

                                                    As with dyadics, an encoded zero or subnormal is tiny. A result delivered as minNormal uses the nearest midpoint, the unbounded-grid predecessor, or minNormal itself according to the rounding direction and sign.

                                                    Instances For
                                                      def FloatLib.Floats.Formats.BinaryInterchange.Model.rationalRoundingStatusScaled (fmt : FloatFormat) (mode : IEEERoundingMode) (sign : Bool) (numerator denominator : ) (exponent : ) (rounded : Model fmt) :

                                                      Classify rounding an exact scaled signed rational to rounded under mode.

                                                      For a nonzero denominator, finite results are compared with the exact rational. Exceptional results are classified as overflow or invalid, as in dyadicRoundingStatus. Division handles a zero denominator before calling this classifier.

                                                      Instances For

                                                        Classify rounding an exact signed rational to rounded under mode.

                                                        Instances For

                                                          Addition with an explicit rounding direction and IEEE exception status.

                                                          Instances For

                                                            Subtraction with an explicit rounding direction and IEEE exception status.

                                                            Instances For

                                                              Multiplication with an explicit rounding direction and IEEE exception status.

                                                              Instances For

                                                                Division with an explicit rounding direction and IEEE exception status.

                                                                Instances For

                                                                  Fused multiply-add with an explicit rounding direction and IEEE exception status.

                                                                  IEEE 754-2019 Section 7.2 leaves it implementation defined whether fma(0, ∞, c) signals invalid when c is a quiet NaN. This implementation signals invalid for that case: the invalid product 0 × ∞ is reported whether or not the addend is a quiet NaN, whereas addWithStatus and mulWithStatus only report an operand-generated invalid operation when no operand is a NaN.

                                                                  Instances For
                                                                    @[inline]

                                                                    Whether a nonnegative dyadic has an exact dyadic square root.

                                                                    When the exponent is odd, one factor of two moves into the significand. The square root is dyadic exactly when the resulting significand is a perfect square.

                                                                    Instances For

                                                                      Square root with an explicit rounding direction and IEEE exception status.

                                                                      Instances For