Documentation

Init.Data.Float.Model.Unpacked.Round

Suppose given a real number x : ℝ with binary expansion x = ± x₀.x₁x₂x₃…. Truncating the expansion at some point gives an approximation of x as a floating-point number y. We can then ask how y is related to x. If y is exactly x, then we say that we are exact. Otherwise we are inexact, and y is slightly smaller than x, but x is also smaller than y + 1ulp. Together with the information that we are inexact, we store the information of where x is located relative to y + ½ulp. This is sufficient information for rounding y according to the various IEEE rounding rules.

  • exact : Accuracy

    The approximation is exactly equal to the infinitely precise value.

  • inexact (relativeToPlusOneHalfUlp : Ordering) : Accuracy

    The approximation is strictly smaller than the infinitely precise value, and the given Ordering describes the result of comparing the infinitely precise value and the approximation plus half a ulp.

Instances For

    Pairs a mantissa with two residual bits, the 'round bit' and the 'sticky bit', which carry precisely the required information to compute the Accuracy of the mantissa.

    • mantissa : Nat

      The mantissa.

    • roundBit : Bool

      The next bit after the least significant bit of the mantissa.

    • stickyBit : Bool

      The bitwise or of all bits that are even less significant than the round bit.

    Instances For

      Extract the accuracy of the mantissa.

      Equations
      Instances For

        Extracts the mantissa, rounded according to the data in the residual bits.

        Equations
        Instances For

          Transforms a mantissa and an accuracy into an extended mantissa with the residual bits initialized to represent the given accuracy.

          Equations
          Instances For

            Shift the mantissa right by one, propagating information into the residual bits as required.

            Equations
            Instances For
              @[instance_reducible]
              Equations
              • One or more equations did not get rendered due to their size.
              def Float.Model.UnpackedFloat.shiftToExponent (mantissa : Nat) (exponent : Int) (accuracy : Accuracy) (targetExponent : Int) :

              Shifts the mantissa and exponent and initial accuracy to the target exponent, returning the new extended mantissa and exponent.

              Important: this function will only drop bits from the mantissa and increase the exponent, not the other way around. The result will only conform to the given specification if the exponent was not too large to begin with. If this may be the case, you should call round instead.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                def Float.Model.UnpackedFloat.shiftToTargetExponent (spec : Format) (mantissa : Nat) (exponent : Int) (accuracy : Accuracy) :

                Computes the target exponent for the given mantissa and exponent and shifts the mantissa and exponent and initial accuracy to the target exponent, returning the new extended mantissa and exponent.

                Important: this function will only drop bits from the mantissa and increase the exponent, not the other way around. The result will only conform to the given specification if the exponent was not too large to begin with. If this may be the case, you should call round instead.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  def Float.Model.UnpackedFloat.roundWithAccuracy (spec : Format) (sign : Sign) (mantissa : Nat) (exponent : Int) (accuracy : Accuracy) :

                  Given a finite float represented by a sign, mantissa and exponent, together with an Accuracy datum, round it to conform to the given Format.

                  Important: this function will only drop bits from the mantissa and increase the exponent, not the other way around. The result will only conform to the given specification if the exponent was not too large to begin with. If this may be the case, you should call round instead.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    def Float.Model.UnpackedFloat.decreaseExponent (mantissa : Nat) (exponent targetExponent : Int) :

                    If the target exponent is smaller than the given exponent, decreases the exponent of the mantissa to the target exponent; otherwise does nothing.

                    Equations
                    Instances For
                      def Float.Model.UnpackedFloat.round (spec : Format) (sign : Sign) (mantissa : Nat) (exponent : Int) :

                      Given a finite float represented by a sign, mantissa and exponent, round it to conform to the given Format.

                      If necessary, this will both decrease and increase the exponent.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        def Float.Model.UnpackedFloat.normalize (spec : Format) (mantissa exponent : Int) (zeroSign : Sign) :

                        Given a finite float represented as a signed mantissa and an exponent, round it to conform to the given Format.

                        If necessary, this will both decrease and increase the exponent.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For