TorchLean API

FloatLib.Floats.Formats.P3109.Arithmetic.Runtime

Exact rational arithmetic for P3109 #

The closed operations in Arithmetic evaluate finite operands in Rat, retaining infinities and the report's single NaN. In particular, division by zero returns NaN, including infinity divided by zero. FMA and fused add-add form the complete exact expression before projection.

The ExecFloat.P3109.*To operations accept independent source and destination descriptors and an explicit projection policy. Same-format operations use FloatLib's nearest-even, no-saturation policy by default. No IEEE exception flags or floating-point environment are used.

Exact rational intermediates can require large integers when the descriptor has a wide exponent range. This implementation does not promise a fixed workspace bound for arbitrary descriptors.

Reference #

IEEE Working Group P3109, Interim Report on Arithmetic Formats for Machine Learning, version 4.0.3 (1 September 2026), §§4.10.1–4.10.8, revision 34f5964. This is an unapproved working-group report, not an approved IEEE standard. https://github.com/P3109/Public/tree/34f5964d9bb2382b2665d15467fc3517b990b308.

The report's single exceptional datum.

Instances For

    Exact rational observation of a decoded binary datum.

    Instances For

      Negation in the report's closed extended domain.

      Instances For

        Absolute value in the report's closed extended domain.

        Instances For

          Copying a sign treats zero as nonnegative and propagates either NaN operand.

          Instances For

            Exact addition; opposite infinities have the indeterminate result NaN.

            Instances For

              Exact subtraction, with no projection of the negated operand.

              Instances For

                Exact division; every zero denominator and infinity divided by infinity yield NaN.

                Instances For

                  Exact reciprocal, before the sole destination projection.

                  Instances For

                    Exact fused multiply-add, with no intermediate rounding or saturation.

                    Instances For

                      Exact fused add-add, with no intermediate rounding or saturation.

                      Instances For
                        @[inline]

                        Exact closed rational value of a P3109 operand.

                        Instances For
                          @[inline]

                          Project an exact unary closed operation into an independently chosen destination.

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

                            Project an exact binary closed operation once, after evaluating both operands.

                            Instances For
                              @[inline]
                              def FloatLib.Floats.ExecFloat.P3109.ternaryTo {leftFormat rightFormat thirdFormat : Formats.P3109.Format} (destination : Formats.P3109.Format) (policy : Formats.P3109.ProjectionPolicy) (operation : Numerics.NumericalValue Numerics.NumericalValue Numerics.NumericalValue Numerics.NumericalValue ) (left : P3109 leftFormat) (right : P3109 rightFormat) (third : P3109 thirdFormat) :
                              P3109 destination

                              Project an exact ternary closed operation once, after the complete expression.

                              Instances For
                                @[inline]

                                Negate and project into the requested destination.

                                Instances For
                                  @[inline]

                                  Take absolute value and project into the requested destination.

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

                                    Copy the sign, propagating either NaN, and project once.

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

                                      Add exact decoded operands and project once.

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

                                        Subtract exact decoded operands and project once.

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

                                          Multiply exact decoded operands and project once.

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

                                            Divide exact decoded operands, returning NaN for a zero denominator, and project once.

                                            Instances For
                                              @[inline]

                                              Take the exact reciprocal and project once.

                                              Instances For
                                                @[inline]
                                                def FloatLib.Floats.ExecFloat.P3109.fmaTo {leftFormat rightFormat thirdFormat : Formats.P3109.Format} (destination : Formats.P3109.Format) (policy : Formats.P3109.ProjectionPolicy) :
                                                P3109 leftFormatP3109 rightFormatP3109 thirdFormatP3109 destination

                                                Fused multiply-add across independently chosen source and destination formats.

                                                Instances For
                                                  @[inline]
                                                  def FloatLib.Floats.ExecFloat.P3109.faaTo {leftFormat rightFormat thirdFormat : Formats.P3109.Format} (destination : Formats.P3109.Format) (policy : Formats.P3109.ProjectionPolicy) :
                                                  P3109 leftFormatP3109 rightFormatP3109 thirdFormatP3109 destination

                                                  Fused add-add across independently chosen source and destination formats.

                                                  Instances For
                                                    @[inline]

                                                    Same-format negation followed by the supplied projection.

                                                    Instances For
                                                      @[inline]

                                                      Same-format absolute value followed by the supplied projection.

                                                      Instances For
                                                        @[inline]

                                                        Same-format sign copying followed by the supplied projection.

                                                        Instances For
                                                          @[inline]

                                                          Same-format addition with one final projection.

                                                          Instances For
                                                            @[inline]

                                                            Same-format subtraction with one final projection.

                                                            Instances For
                                                              @[inline]

                                                              Same-format multiplication with one final projection.

                                                              Instances For
                                                                @[inline]

                                                                Same-format division with one final projection; a zero denominator yields NaN.

                                                                Instances For
                                                                  @[inline]

                                                                  Same-format reciprocal with one final projection.

                                                                  Instances For
                                                                    @[inline]

                                                                    Same-format fused multiply-add with one final projection.

                                                                    Instances For
                                                                      @[inline]

                                                                      Same-format fused add-add with one final projection.

                                                                      Instances For