TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Conversion.Runtime

Binary-interchange conversion runtime #

Every binary-interchange family uses the same representation-independent conversion policy. A concrete carrier supplies only a pack function from its Model format; configured machine-word formats and nominal static-byte formats therefore share one exact quantizer.

The exact domain is SignedRat, so the sign of a zero input reaches the destination. Finite values are rounded once by Model.Policy.roundRat, with the sign bit taken from the signed rational and the magnitude from its value. Infinity and exceptional observations use separate explicit policies because finite-only formats cannot preserve every IEEE value class. Status flags are computed from exact rational comparisons, never through a host floating-point value.

specWith pack preserves the complete executable outcome and adds an independent nearest-value predicate for nearest-even/native-overflow/gradual-underflow conversion to conventional IEEE descriptors. Its proof uses the descriptor's real rounding semantics. The nearest-value clause applies when the delivered model has a finite rational denotation; overflow, tie selection, signed zero, status, and the other policies retain the complete executable-outcome clause.

Policy for an infinity presented to a binary-interchange destination.

  • preserve : InfinityPolicy

    Preserve infinity when the destination encoding supports it; otherwise reject the cast.

  • saturate : InfinityPolicy

    Clamp infinity to the finite destination value of greatest magnitude with the same sign.

  • reject : InfinityPolicy

    Reject infinity even when the destination could represent it.

Instances For

    Policy for NaN, NaR, reserved, or undefined observations.

    Instances For

      Complete explicit context for conversion into a binary-interchange destination.

      Instances For

        Canonical binary conversion context.

        Finite values use nearest-even/native-overflow/gradual-underflow behavior. Infinities and exceptional values retain their value class when the destination encoding supports that class; otherwise conversion fails explicitly.

        Instances For
          @[inline]

          Canonical conversion context with one caller-selected finite rounding direction.

          Native overflow, gradual underflow, infinity preservation, and canonical-NaN mapping retain their default behavior. Use a record update when any of those policies must also change.

          Instances For
            @[inline]

            Exact addition with the destination's cancellation-sign rule, before rounding.

            Instances For
              @[inline]

              Exact subtraction applies the same cancellation rule to the negated right operand.

              Instances For
                @[inline]

                Status derived from exact rational binary rounding.

                Overflow and tininess use the precision-rounded value with an unbounded exponent range. Merely exceeding the largest finite value does not signal overflow when rounding brings the value back into range. Nearest-away and stochastic policies use their own integer rounding rule, including the supplied entropy, at the same precision boundary.

                Instances For
                  @[inline]

                  Round one finite signed rational and pack the resulting binary model into a destination carrier.

                  The sign bit of the result comes from exact.negative, so a negative zero rounds to the destination's negative zero when the encoding has one. pack is the only representation-specific argument. It is deliberately applied after exact rounding, so changing storage or an execution backend cannot change numerical meaning.

                  Instances For
                    @[inline]

                    Apply the exceptional-value policy and pack a supported canonical NaN.

                    Instances For
                      @[inline]

                      Apply the infinity policy and pack the selected binary model value.

                      Instances For
                        @[inline]

                        Reference conversion shared by every carrier for the same binary descriptor.

                        Instances For

                          A finite rounded denotation is no farther from the input than any finite destination value.

                          Instances For

                            Complete conversion outcome, together with an independent nearest-value clause for IEEE defaults.

                            The rational predicate is runtime-free: its proof uses real rounding only in Conversion.Proof. Complete outcome equality additionally preserves overflow, tie selection, zero signs, all status fields, and every nondefault policy. A nonfinite result has no nearest finite denotation.

                            Instances For