Documentation

Fp.Basic

Packed Floating Point Numbers #

This is a test module description

structure PackedFloat (exWidth sigWidth : Nat) :

A packed floating point number, whose exponent and significand width are encoded at the type level.

  • sign : Bool

    Sign bit.

  • ex : BitVec exWidth

    Exponent of the packed float.

  • sig : BitVec sigWidth

    Significand (mantissa) of the packed float.

Instances For
    instance instDecidableEqPackedFloat {exWidth✝ sigWidth✝ : Nat} :
    DecidableEq (PackedFloat exWidth✝ sigWidth✝)
    Equations
    instance instReprPackedFloat {exWidth✝ sigWidth✝ : Nat} :
    Repr (PackedFloat exWidth✝ sigWidth✝)
    Equations
    instance instReprPackedFloat_1 {exWidth sigWidth : Nat} :
    Repr (PackedFloat exWidth sigWidth)
    Equations
    • One or more equations did not get rendered due to their size.
    structure FixedPoint (width exOffset : Nat) :

    A fixed point number with specified exponent offset.

    • sign : Bool
    • val : BitVec width
    • hExOffset : exOffset < width
    Instances For
      instance instDecidableEqFixedPoint {width✝ exOffset✝ : Nat} :
      DecidableEq (FixedPoint width✝ exOffset✝)
      Equations
      instance instReprFixedPoint {width ExOffset : Nat} :
      Repr (FixedPoint width ExOffset)
      Equations
      • One or more equations did not get rendered due to their size.
      inductive State :

      The "state" of an extended fixed-point number: either NaN, infinity, or a number.

      Instances For
        Equations
        Equations
        • One or more equations did not get rendered due to their size.
        structure EFixedPoint (width exOffset : Nat) :

        A fixed point number extended with infinity and NaN.

        Instances For
          instance instDecidableEqEFixedPoint {width✝ exOffset✝ : Nat} :
          DecidableEq (EFixedPoint width✝ exOffset✝)
          Equations
          instance instReprEFixedPoint {width✝ exOffset✝ : Nat} :
          Repr (EFixedPoint width✝ exOffset✝)
          Equations
          def FixedPoint.equal {w e : Nat} (a b : FixedPoint w e) :
          Equations
          Instances For
            theorem FixedPoint.injEq {w e : Nat} (a b : FixedPoint w e) :
            (a = b) = (a.sign = b.sign a.val = b.val)
            theorem FixedPoint.inj {w e : Nat} (a b : FixedPoint w e) :
            a.sign = b.sign a.val = b.vala = b
            theorem FixedPoint.equal_refl {w e : Nat} (a : FixedPoint w e) :
            theorem FixedPoint.equal_comm {w e : Nat} (a b : FixedPoint w e) :
            a.equal b = b.equal a
            def FixedPoint.expand {w e : Nat} (a : FixedPoint w e) (w' e' : Nat) (he : e' e) (hw : w' + e w + e') :
            Equations
            Instances For
              theorem EFixedPoint.injEq {w e : Nat} (a b : EFixedPoint w e) :
              (a = b) = (a.state = b.state a.num.sign = b.num.sign a.num.val = b.num.val)
              theorem EFixedPoint.inj {w e : Nat} (a b : EFixedPoint w e) :
              a.state = b.state a.num.sign = b.num.sign a.num.val = b.num.vala = b
              def EFixedPoint.getNaN {sigWidth exWidth : Nat} (hExOffset : sigWidth < exWidth) :
              EFixedPoint exWidth sigWidth
              Equations
              Instances For
                def EFixedPoint.getInfinity {sigWidth exWidth : Nat} (sign : Bool) (hExOffset : sigWidth < exWidth) :
                EFixedPoint exWidth sigWidth
                Equations
                Instances For
                  def EFixedPoint.zero {sigWidth exWidth : Nat} (hExOffset : sigWidth < exWidth) :
                  EFixedPoint exWidth sigWidth
                  Equations
                  Instances For
                    def EFixedPoint.equal {w e : Nat} (a b : EFixedPoint w e) :

                    Floating point equality test. Recall that NaN ≠ Nan under the floating point semantics.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      def EFixedPoint.equal_or_nan {w e : Nat} (a b : EFixedPoint w e) :
                      Equations
                      Instances For

                        Floating point equality test, where we check up to denotation. So, under this definition:

                        • NaN = Nan iff the states are both Nan.
                        • +Infinity = +Infinity, -Infinity = -Infinity.
                        • Number equality is reflexive.
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          def EFixedPoint.isNaN {w e : Nat} (a : EFixedPoint w e) :
                          Equations
                          Instances For
                            def EFixedPoint.isZero {w e : Nat} (a : EFixedPoint w e) :
                            Equations
                            Instances For
                              def EFixedPoint.expand {w e : Nat} (a : EFixedPoint w e) (w' e' : Nat) (he : e' e) (hw : w' + e w + e') :
                              Equations
                              Instances For
                                def PackedFloat.getNaN (exWidth sigWidth : Nat) :
                                PackedFloat exWidth sigWidth

                                Returns the "canonical" NaN for the given floating point format. For example, the canonical NaN for exWidth = 3 and sigWidth = 4 is 0.111.1000.

                                Equations
                                Instances For
                                  def PackedFloat.getInfinity (exWidth sigWidth : Nat) (sign : Bool) :
                                  PackedFloat exWidth sigWidth

                                  Returns the infinity value of the specified sign for the given floating point format.

                                  Equations
                                  Instances For
                                    def PackedFloat.getZero (exWidth sigWidth : Nat) :
                                    PackedFloat exWidth sigWidth

                                    Returns the (positive) zero value for the given floating point format.

                                    Equations
                                    Instances For
                                      def PackedFloat.getMax (exWidth sigWidth : Nat) (sign : Bool) :
                                      PackedFloat exWidth sigWidth

                                      Returns the maximum (magnitude) value for the given sign.

                                      Equations
                                      Instances For
                                        theorem PackedFloat.injEq {e s : Nat} (a b : PackedFloat e s) :
                                        (a = b) = (a.sign = b.sign a.ex = b.ex a.sig = b.sig)
                                        theorem PackedFloat.inj {e s : Nat} (a b : PackedFloat e s) :
                                        a.sign = b.sign a.ex = b.ex a.sig = b.siga = b
                                        def PackedFloat.isInfinite {e s : Nat} (pf : PackedFloat e s) :
                                        Equations
                                        Instances For
                                          def PackedFloat.isNaN {e s : Nat} (pf : PackedFloat e s) :
                                          Equations
                                          Instances For
                                            Equations
                                            Instances For
                                              Equations
                                              Instances For
                                                def PackedFloat.isZero {e s : Nat} (pf : PackedFloat e s) :
                                                Equations
                                                Instances For
                                                  def PackedFloat.isNZero {e s : Nat} (pf : PackedFloat e s) :
                                                  Equations
                                                  Instances For
                                                    def PackedFloat.isPZero {e s : Nat} (pf : PackedFloat e s) :
                                                    Equations
                                                    Instances For
                                                      Equations
                                                      Instances For
                                                        def PackedFloat.ofBits (e s : Nat) (b : BitVec (1 + e + s)) :

                                                        Returns the PackedFloat representation for the given BitVec.

                                                        Equations
                                                        Instances For
                                                          def PackedFloat.toBits {e s : Nat} (x : PackedFloat e s) :
                                                          BitVec (1 + e + s)

                                                          Returns the BitVec representation for the given PackedFloat.

                                                          Equations
                                                          Instances For
                                                            def PackedFloat.toEFixed {e s : Nat} (pf : PackedFloat e s) :
                                                            EFixedPoint (2 ^ e + s) (2 ^ (e - 1) + s - 2)

                                                            Convert from a packed float to a fixed point number.

                                                            Conversion function assumes IEEE compliance. For output FixedPoint number to have a non-degenerate exponent offset, we need two or more bits in the exponent.

                                                            NOTE: Assuming IEEE compliance, you technically only need 2^e + s - 2 bits to cover the entire range of representable values.

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

                                                                E5M2 floating point representation of 1.0

                                                                Equations
                                                                Instances For

                                                                  E5M2 floating point representation of 2.0

                                                                  Equations
                                                                  Instances For

                                                                    Smallest (positive) normal number in E5M2 floating point.

                                                                    Equations
                                                                    Instances For

                                                                      Smallest (positive) subnormal number in E5M2 floating point.

                                                                      Equations
                                                                      Instances For