TorchLean API

FloatLib.Floats.Formats.DecimalInterchange.Projection.Runtime

Cohort-aware rational projection #

Precision rounding precedes the overflow test (IEEE 754-2019 §7.4). Decimal tininess is detected before rounding (§7.5), and the underflow flag requires both tininess and inexactness. Exact results select the cohort member closest to the preferred quantum (§5.2). projectMagnitude requires a nonnegative input. project handles either sign and takes the sign of an exact zero as its own argument.

A decimal result with the exceptions raised by this operation.

Instances For

    Least positive normal value, independent of the chosen cohort.

    Instances For

      Greatest finite magnitude with sign negative, in its largest-quantum representation.

      Instances For

        Precision-rounded coefficient and exponent with an unbounded upper exponent. The only possible carry is exactly 10 ^ precision.

        Instances For

          Whether overflow delivers an infinity rather than the greatest finite value.

          Instances For
            def FloatLib.Floats.Formats.DecimalInterchange.projectMagnitude (f : Format) (mode : RoundingMode) (negative : Bool) (magnitude : ℚ) (preferred : ℤ) :

            Project a nonnegative rational magnitude, retaining the supplied sign even at zero. Exact zero selects its cohort without forming the powers used for rounding or tininess.

            Instances For

              Clamp the exponent of coefficient * 10^exponent to a range where projection stays cheap.

              A zero coefficient gets exponent zero. Otherwise the exponent is kept between a lower bound, where the magnitude is below half the least subnormal quantum, and maxQuantum + precision, where it overflows. projectScaled_eq proves that projecting the clamped magnitude gives the same outcome.

              Instances For
                def FloatLib.Floats.Formats.DecimalInterchange.projectScaled (f : Format) (mode : RoundingMode) (negative : Bool) (coefficient : ℕ) (exponent preferred : ℤ) :

                Project the exact magnitude coefficient * 10^exponent with a preferred quantum.

                The exponent is clamped with clampScaledExponent before the power of ten is formed, so huge exponents such as 10^(10^12) are never materialized. The outcome equals projectMagnitude f mode negative (coefficient * 10^exponent) preferred.

                Instances For
                  def FloatLib.Floats.Formats.DecimalInterchange.project (f : Format) (mode : RoundingMode) (value : ℚ) (preferred : ℤ) (negativeZero : Bool := false) :

                  Round an exact rational value with an operation's preferred quantum. negativeZero is consulted only when the exact input equals zero.

                  Instances For