packages feed

posit 3.2.0.3 → 3.2.0.4

raw patch · 6 files changed

+112/−29 lines, 6 filesdep +vectordep +weighPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: vector, weigh

API changes (from Hackage documentation)

- Posit.Internal.PositC: instance Foreign.Storable.Storable Data.DoubleWord.Int128
- Posit.Internal.PositC: instance Foreign.Storable.Storable Data.DoubleWord.Int256
- Posit.Internal.PositC: instance Foreign.Storable.Storable Data.DoubleWord.Word128
+ Posit: instance Control.DeepSeq.NFData (Posit.Posit es)
+ Posit.Internal.PositC: instance Data.BinaryWord.BinaryWord Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance Data.BinaryWord.BinaryWord Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance Data.BinaryWord.BinaryWord Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance Data.DoubleWord.Base.DoubleWord Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance Data.DoubleWord.Base.DoubleWord Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance Data.DoubleWord.Base.DoubleWord Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance Foreign.Storable.Storable Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance Foreign.Storable.Storable Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance Foreign.Storable.Storable Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance GHC.Bits.Bits Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance GHC.Bits.Bits Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance GHC.Bits.Bits Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance GHC.Bits.FiniteBits Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance GHC.Bits.FiniteBits Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance GHC.Bits.FiniteBits Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance GHC.Classes.Eq Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance GHC.Classes.Eq Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance GHC.Classes.Eq Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance GHC.Classes.Ord Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance GHC.Classes.Ord Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance GHC.Classes.Ord Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance GHC.Enum.Bounded Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance GHC.Enum.Bounded Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance GHC.Enum.Bounded Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance GHC.Enum.Enum Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance GHC.Enum.Enum Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance GHC.Enum.Enum Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance GHC.Num.Num Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance GHC.Num.Num Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance GHC.Num.Num Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance GHC.Read.Read Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance GHC.Read.Read Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance GHC.Read.Read Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance GHC.Real.Integral Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance GHC.Real.Integral Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance GHC.Real.Integral Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance GHC.Real.Real Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance GHC.Real.Real Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance GHC.Real.Real Posit.Internal.PositC.Word128_Storable
+ Posit.Internal.PositC: instance GHC.Show.Show Posit.Internal.PositC.Int128_Storable
+ Posit.Internal.PositC: instance GHC.Show.Show Posit.Internal.PositC.Int256_Storable
+ Posit.Internal.PositC: instance GHC.Show.Show Posit.Internal.PositC.Word128_Storable

Files

ChangeLog.md view
@@ -1,5 +1,14 @@ # Changelog for Posit Numbers +# posit-3.2.0.4++  * No more Orphan Instances for Storable!+  * Figured out how to resolve the orphan instances problem with `newtype`, `DerivingVia` and `UndecidableInstances`.+  * Added a "weigh" based test to verify the proper size of each Posit type+  * Added a WeighPosit test; command to run: stack test posit:test-posit-weigh+  * Added NFData instance.+  * New GitHub Snapshot of Liquid Haskell makes it work with GHC 9.0.2!+ # posit-3.2.0.3    * Made the following changes in anticipation of adding the 2022 Posit Standard:
README.md view
@@ -1,4 +1,4 @@-# posit 3.2.0.3+# posit 3.2.0.4  The [Posit Standard 3.2](https://posithub.org/docs/posit_standard.pdf), where Real numbers are approximated by Maybe Rational.  The Posit @@ -25,7 +25,7 @@  * Floating  -- Mathematical functions such as logarithm, exponential, trigonometric, and hyperbolic functions. Warning! May induce trance.  The Posits are indexed by the type (es :: ES) where exponent size and-word size are related.  In `posit-3.2.0.3` es is instantiated as Z, I,+word size are related.  In `posit-3.2.0.4` es is instantiated as Z, I, II, III, IV, V.  The word size (in bits) of the value is `= 8 * 2^es`, that is `2^es` bytes.  The Types: 'Posit8', 'Posit16', 'Posit32', 'Posit64', 'Posit128', and 'Posit256' are implemented and include a
posit.cabal view
@@ -1,7 +1,7 @@ cabal-version: 1.12  name:           posit-version:        3.2.0.3+version:        3.2.0.4 description:    The Posit Number format.  Please see the README on GitHub at <https://github.com/waivio/posit#readme> homepage:       https://github.com/waivio/posit#readme bug-reports:    https://github.com/waivio/posit/issues@@ -11,6 +11,11 @@ license:        BSD3 license-file:   LICENSE build-type:     Simple+tested-with:         GHC == 8.10.4,+                     GHC == 8.10.7,+                     GHC == 9.0.2,+                     GHC == 9.2.5,+                     GHC == 9.4.4 extra-source-files:     README.md     ChangeLog.md@@ -24,11 +29,6 @@   manual:      True   default:     False -flag do-no-orphans-  description: Build without Orphan Instances if data-dword gets updated for Storable Instances-  manual:      True-  default:     False- flag do-liquid   description: Build with Liquid Haskell checking   manual:      True@@ -60,9 +60,6 @@   if flag(do-no-storable)     cpp-options: -DO_NO_STORABLE  -  if flag(do-no-orphans)-    cpp-options: -DO_NO_ORPHANS-    if flag(do-liquid)     cpp-options: -DO_LIQUID -DO_NO_STORABLE  @@ -93,4 +90,17 @@   build-depends:       base >=4.7 && <5     , posit+  default-language: Haskell2010++-- Weigh based benchmark for Vector+benchmark test-posit-weigh+  type: exitcode-stdio-1.0+  hs-source-dirs: test+  main-is: WeighPosit.hs+  ghc-options: -Wall -O2+  build-depends:+    posit,+    base >=4.7 && <5,+    vector,+    weigh   default-language: Haskell2010
src/Posit.hs view
@@ -154,6 +154,9 @@ import GHC.Natural (Natural) -- Import the Natural Numbers ℕ (u+2115) for some of the Transcendental Functions import Data.Ratio ((%))  -- Import the Rational Numbers ℚ (u+211A), ℚ can get arbitrarily close to Real numbers ℝ (u+211D), used for some of the Transcendental Functions +-- for NFData instance+import Control.DeepSeq (NFData, rnf)+ import Debug.Trace (trace) -- temporary for debug purposes  @@ -168,6 +171,10 @@ -- |Base GADT rapper type, that uses the Exponent Size kind to index the various implementations data Posit (es :: ES) where      Posit :: PositC es => !(IntN es) -> Posit es++-- |NFData Instance+instance NFData (Posit es) where+  rnf (Posit _) = ()  -- |Not a Real Number, the Posit is like a Maybe type, it's either a real number or not pattern NaR :: forall es. PositC es => Posit es
src/Posit/Internal/PositC.hs view
@@ -22,6 +22,8 @@ {-# LANGUAGE FlexibleContexts #-} -- To reduce some code duplication by claiming the type family provides some constraints, that GHC can't do without fully evaluating the type family {-# LANGUAGE ConstrainedClassMethods #-} -- Allows constraints on class methods so default implementations of methods with Type Families can be implemented {-# LANGUAGE ConstraintKinds #-}  -- Simplify all of the constraints into a combinded constraint for the super class constraint+{-# LANGUAGE DerivingVia #-}  -- To Derive instances for newtypes to eliminate Orphan Instances+{-# LANGUAGE UndecidableInstances #-}  -- For deriving DoubleWord {-# LANGUAGE CPP #-} -- To remove Storable instances to remove noise when performing analysis of Core {-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}  -- Turn off noise {-# OPTIONS_GHC -Wno-type-defaults #-}  -- Turn off noise@@ -50,9 +52,9 @@ {-@ embed Int128 * as int @-} {-@ embed Int256 * as int @-} import Data.Int (Int8,Int16,Int32,Int64)  -- Import standard Int sizes-import Data.DoubleWord (Word128,Int128,Int256,fromHiAndLo,hiWord,loWord) -- Import large Int sizes+import Data.DoubleWord (Word128,Int128,Int256,fromHiAndLo,hiWord,loWord,DoubleWord,BinaryWord) -- Import large Int sizes import Data.Word (Word64)-import Data.Bits (Bits(..), (.|.), shiftL, shift, testBit, (.&.), shiftR)+import Data.Bits (Bits(..), (.|.), shiftL, shift, testBit, (.&.), shiftR,FiniteBits)  -- Import Naturals and Rationals {-@ embed Natural * as int @-}@@ -79,9 +81,26 @@     IntN I   = Int16     IntN II  = Int32     IntN III = Int64+#ifdef O_NO_STORABLE     IntN IV  = Int128     IntN V   = Int256+#endif+#ifndef O_NO_STORABLE+    IntN IV  = Int128_Storable+    IntN V   = Int256_Storable +-- | New Type Wrappers to resolve Orphan Instance Issue+newtype Int128_Storable = Int128_Storable Int128+  deriving (Bits,Bounded,Enum,Real,Integral,Eq,Ord,Num,Read,Show,DoubleWord,BinaryWord,FiniteBits)+    via Int128+newtype Int256_Storable = Int256_Storable Int256+  deriving (Bits,Bounded,Enum,Real,Integral,Eq,Ord,Num,Read,Show,DoubleWord,BinaryWord,FiniteBits)+    via Int256+newtype Word128_Storable = Word128_Storable Word128+  deriving (Bits,Bounded,Enum,Real,Integral,Eq,Ord,Num,Read,Show,DoubleWord,BinaryWord,FiniteBits)+    via Word128+#endif+ -- | The 'FixedWidthInteger' is a Constraint Synonym that contains all -- of the constraints provided by the 'IntN' Type Family.  It is a super -- class for the Posit Class.@@ -370,14 +389,13 @@ xnor a b = not $ (a || b) && not (b && a)  -#ifndef O_NO_ORPHANS #ifndef O_NO_STORABLE -- ===================================================================== -- ===                  Storable Instances                           === -- ===================================================================== ----- Orphan Instance for Word128 using the DoubleWord type class-instance Storable Word128 where+-- Storable Instance for Word128 using the DoubleWord type class and Word128_Storable newtype+instance Storable Word128_Storable where   sizeOf _ = 16   alignment _ = 16   peek ptr = do@@ -392,8 +410,8 @@       where         offsetWord i = (castPtr ptr :: Ptr Word64) `plusPtr` (i*8) --- Orphan Instance for Int128 using the DoubleWord type class-instance Storable Int128 where+-- Storable Instance for Int128 using the DoubleWord type class and Int128_Storable newtype+instance Storable Int128_Storable where   sizeOf _ = 16   alignment _ = 16   peek ptr = do@@ -410,23 +428,23 @@         offsetInt i = (castPtr ptr :: Ptr Int64) `plusPtr` (i*8)         offsetWord i = (castPtr ptr :: Ptr Word64) `plusPtr` (i*8) --- Orphan Instance for Int256 using the DoubleWord type class-instance Storable Int256 where+-- Storable Instance for Int256 using the DoubleWord type class and Int256_Storable newtype+instance Storable Int256_Storable where   sizeOf _ = 32   alignment _ = 32   peek ptr = do-    hi <- peek $ offsetInt 0-    lo <- peek $ offsetWord 1+    (Int128_Storable hi) <- peek $ offsetInt 0+    (Word128_Storable lo) <- peek $ offsetWord 1     return $ fromHiAndLo hi lo       where-        offsetInt i = (castPtr ptr :: Ptr Int128) `plusPtr` (i*16)-        offsetWord i = (castPtr ptr :: Ptr Word128) `plusPtr` (i*16)+        offsetInt i = (castPtr ptr :: Ptr Int128_Storable) `plusPtr` (i*16)+        offsetWord i = (castPtr ptr :: Ptr Word128_Storable) `plusPtr` (i*16)   poke ptr int = do-    poke (offsetInt 0) (hiWord int)-    poke (offsetWord 1) (loWord int)+    poke (offsetInt 0) (Int128_Storable $ hiWord int)+    poke (offsetWord 1) (Word128_Storable $ loWord int)       where-        offsetInt i = (castPtr ptr :: Ptr Int128) `plusPtr` (i*16)-        offsetWord i = (castPtr ptr :: Ptr Word128) `plusPtr` (i*16)+        offsetInt i = (castPtr ptr :: Ptr Int128_Storable) `plusPtr` (i*16)+        offsetWord i = (castPtr ptr :: Ptr Word128_Storable) `plusPtr` (i*16) -- #endif-#endif+
+ test/WeighPosit.hs view
@@ -0,0 +1,39 @@+import Weigh+import Data.Vector.Storable as V++import Posit+import Posit.Internal.PositC++main :: IO ()+main = mainWith $ do+  func' "Posit8 in 1M Vector" vecOf unitPosit8+  func' "Posit16 in 1M Vector" vecOf unitPosit16+  func' "Posit32 in 1M Vector" vecOf unitPosit32+  func' "Posit64 in 1M Vector" vecOf unitPosit64+  func' "Posit128 in 1M Vector" vecOf unitPosit128+  func' "Posit256 in 1M Vector" vecOf unitPosit256+++vecOf :: PositC es => Posit es -> V.Vector (Posit es)+vecOf x = V.replicate (1024*1024) x++unitPosit8 :: Posit8+unitPosit8 = 1++unitPosit16 :: Posit16+unitPosit16 = 1++unitPosit32 :: Posit32+unitPosit32 = 1++unitPosit64 :: Posit64+unitPosit64 = 1++unitPosit128 :: Posit128+unitPosit128 = 1++unitPosit256 :: Posit256+unitPosit256 = 1+++