hmpfr 0.3.2 → 0.3.3
raw patch · 8 files changed
+107/−67 lines, 8 filesdep +integer-gmp
Dependencies added: integer-gmp
Files
- demo/Demo.hs +8/−9
- hmpfr.cabal +29/−13
- src/Data/Number/MPFR/Assignment.hs +13/−5
- src/Data/Number/MPFR/Instances/Down.hs +14/−10
- src/Data/Number/MPFR/Instances/Near.hs +14/−10
- src/Data/Number/MPFR/Instances/Up.hs +14/−9
- src/Data/Number/MPFR/Instances/Zero.hs +14/−10
- src/Data/Number/MPFR/Mutable/Internal.hs +1/−1
demo/Demo.hs view
@@ -1,4 +1,4 @@-module Demo where+module Main where import qualified Data.Number.MPFR as M --import functions import Data.Number.MPFR.Instances.Up -- import instances@@ -61,15 +61,14 @@ print $ M.urandomb rsP 1000 print $ M.urandomb rsP 1000 -main = do print $ s1 1000 1000- print $ s6 1000 1000- print $ e1 1000 1000- print $ e2 1000 1000+main = do print $ s1 1000 100000+ print $ s6 1000 100000+ print $ e1 1000 100000+ print $ e2 1000 100000 testRandom- putStrLn $ "exp 1 = " ++ (M.toStringExp 10000 $ M.exp M.Up 100 one)- putStrLn $ "exp -1 = " ++ (M.toStringExp 10000 $ M.exp M.Up 100 (M.neg M.Up 100 one))- putStrLn $ "exp 1 = " ++ (M.toStringExp 10000 $ M.exp M.Up 100 one)- putStrLn $ "exp -1 = " ++ (M.toStringExp 10000 $ M.exp M.Up 100 (M.neg M.Up 100 one))+ let c1 = one+ putStrLn $ "exp 1 = " ++ (M.toStringExp 10000 $ M.exp M.Up 100 c1)+ putStrLn $ "exp -1 = " ++ (M.toStringExp 10000 $ M.exp M.Up 100 (M.neg M.Up 100 c1)) one = 1 :: M.MPFR
hmpfr.cabal view
@@ -1,41 +1,57 @@ name: hmpfr-version: 0.3.2+version: 0.3.3 synopsis: Haskell binding to the MPFR library description: Haskell binding to the MPFR library. This version is compatible with MPFR 2.4.* and later and will not work with previous releases of the MPFR library. .- /Since MPFR uses GMP, this library does not work correctly/- /with a ghc that has been compiled with integer-gmp./ - /When using ghc, this library will require that the ghc/- /is compiled with integer-simple./+ /Since MPFR uses GMP, this library features infrequent but serious errors/+ /with a ghc (at least <= 7.2.1) that has been compiled with integer-gmp./ + /When using ghc, it is recommended to use one compiled with integer-simple./ .- The library includes a mutable interface- in addition to the pure one. These functions should have a- lot less overhead than the pure ones.+ The library includes both a pure and a mutable interface.+ The mutable interface should have a lot less overhead + than the pure one. . Some simple examples of usage can be found in demo/Demo.hs. category: Data, Math license: BSD3 license-file: LICENSE Stability: experimental-tested-with: GHC == 6.12.3+tested-with: GHC == 6.12.3, GHC == 7.2.1 author: Aleš Bizjak, Michal Konečný maintainer: Michal Konečný <mikkonecny@gmail.com> Homepage: http://code.google.com/p/hmpfr/- build-type: Simple-cabal-version: >= 1.2+cabal-version: >= 1.6 Extra-source-files: demo/Demo.hs Data-files: README dict.txt ChangeLog +source-repository head+ type: mercurial+ location: https://code.google.com/p/hmpfr/++source-repository this+ type: mercurial+ location: https://code.google.com/p/hmpfr/+ tag: 0.3.3+++flag use-integer-simple+ description: Use this when compiling using a ghc that uses integer-simple instead of integer-gmp.+ default: False+ Library build-Depends: base > 3 && < 5- if impl(ghc)+ if flag(use-integer-simple) build-Depends: integer-simple+ cpp-options: -DINTEGER_SIMPLE+ else+ build-Depends: integer-gmp+ cpp-options: -DINTEGER_GMP Other-modules: Data.Number.MPFR.FFIhelper Data.Number.MPFR.Internal@@ -64,7 +80,7 @@ Data.Number.MPFR.Mutable build-tools: hsc2hs- GHC-options: -Wall -fno-warn-orphans -O2+ GHC-options: -Wall -fno-warn-orphans GHC-prof-options: -prof -auto hs-source-dirs: src include-dirs: cbits
src/Data/Number/MPFR/Assignment.hs view
@@ -22,12 +22,15 @@ import Foreign.Storable -#if (__GLASGOW_HASKELL__ >= 610) && (__GLASGOW_HASKELL__ < 612)-#error "hmpfr can be compiled only with ghc 6.12 or newer with integer-simple" -#elif __GLASGOW_HASKELL__ >= 612+#ifdef INTEGER_SIMPLE import GHC.Integer.Simple.Internals #endif +#ifdef INTEGER_GMP+--import GHC.Integer.GMP.Internals+import GHC.Float+#endif+ set :: RoundMode -> Precision -> MPFR -> MPFR set r p = fst . set_ r p @@ -137,15 +140,20 @@ fromIntegerA r p = stringToMPFR r p 10 . show bitsInInteger :: (Num a) => Integer -> a++# ifdef INTEGER_SIMPLE bitsInInteger Naught = 0 bitsInInteger (Positive pos) = bitsInPositive pos bitsInInteger (Negative pos) = bitsInPositive pos bitsInPositive :: (Num a) => Positive -> a bitsInPositive None = 0 bitsInPositive (Some _ rest) = - sizeofInt + (bitsInPositive rest)+ (8 * sizeofInt) + (bitsInPositive rest) sizeofInt :: (Num a) => a -sizeofInt = fromIntegral $ sizeOf (0 :: Int)+sizeofInt = fromIntegral $ sizeOf (0 :: Int) -- in bytes+#else+bitsInInteger = fromIntegral . GHC.Float.integerLogBase 2+#endif compose :: RoundMode -> Precision -> (Integer, Int) -> MPFR compose r p (i, ii) = div2i r p (fromIntegerA r p i) ii
src/Data/Number/MPFR/Instances/Down.hs view
@@ -1,4 +1,4 @@--- {-# LANGUAGE MagicHash, CPP #-}+{-# LANGUAGE MagicHash, CPP #-} {-| Module : Data.Number.MPFR.Instances.Down Description : Instance declarations@@ -31,15 +31,15 @@ import Data.Ratio +#ifdef INTEGER_SIMPLE+--import GHC.Integer.Simple.Internals+#endif+#ifdef INTEGER_GMP+import GHC.Integer.GMP.Internals+import qualified GHC.Exts as E+#endif --- #if (__GLASGOW_HASKELL__ >= 610) && (__GLASGOW_HASKELL__ < 612)--- import GHC.Integer.Internals--- #elif __GLASGOW_HASKELL__ >= 612--- import GHC.Integer.GMP.Internals--- #endif --- import qualified GHC.Exts as E- instance Num MPFR where d + d' = A.add Down (maxPrec d d') d d' d - d' = A.sub Down (maxPrec d d') d d'@@ -47,10 +47,14 @@ negate d = A.neg Down (getPrec d) d abs d = A.absD Down (getPrec d) d signum = fromInt Down minPrec . fromMaybe (-1) .sgn+#ifdef INTEGER_SIMPLE fromInteger i = fromIntegerA Down (max minPrec $ 1 + bitsInInteger i) i--- fromInteger (S# i) = fromInt Down minPrec (E.I# i)--- fromInteger i@(J# n _) = fromIntegerA Zero (fromIntegral . abs $ E.I# n * bitsPerIntegerLimb) i +#endif+#ifdef INTEGER_GMP+ fromInteger (S# i) = fromInt Down minPrec (E.I# i)+ fromInteger i@(J# n _) = fromIntegerA Zero (fromIntegral . abs $ E.I# n * bitsPerIntegerLimb) i +#endif instance Real MPFR where toRational d = n % 2 ^ e
src/Data/Number/MPFR/Instances/Near.hs view
@@ -1,4 +1,4 @@--- {-# LANGUAGE MagicHash, CPP #-}+{-# LANGUAGE MagicHash, CPP #-} {-| Module : Data.Number.MPFR.Instances.Near Description : Instance declarations@@ -30,13 +30,13 @@ import Data.Ratio --- #if (__GLASGOW_HASKELL__ >= 610) && (__GLASGOW_HASKELL__ < 612)--- import GHC.Integer.Internals--- #elif __GLASGOW_HASKELL__ >= 612--- import GHC.Integer.GMP.Internals--- #endif---- import qualified GHC.Exts as E+#ifdef INTEGER_SIMPLE+--import GHC.Integer.Simple.Internals+#endif+#ifdef INTEGER_GMP+import GHC.Integer.GMP.Internals+import qualified GHC.Exts as E+#endif instance Num MPFR where d + d' = A.add Near (maxPrec d d') d d'@@ -45,10 +45,14 @@ negate d = A.neg Near (getPrec d) d abs d = A.absD Near (getPrec d) d signum = fromInt Near minPrec . fromMaybe (-1) . sgn+#ifdef INTEGER_SIMPLE fromInteger i = fromIntegerA Near (max minPrec $ 1 + bitsInInteger i) i--- fromInteger (S# i) = fromInt Zero minPrec (E.I# i)--- fromInteger i@(J# n _) = fromIntegerA Zero (fromIntegral . abs $ E.I# n * bitsPerIntegerLimb) i +#endif+#ifdef INTEGER_GMP+ fromInteger (S# i) = fromInt Near minPrec (E.I# i)+ fromInteger i@(J# n _) = fromIntegerA Zero (fromIntegral . abs $ E.I# n * bitsPerIntegerLimb) i +#endif instance Real MPFR where toRational d = n % 2 ^ e
src/Data/Number/MPFR/Instances/Up.hs view
@@ -1,4 +1,4 @@--- {-# LANGUAGE MagicHash, CPP #-}+{-# LANGUAGE MagicHash, CPP #-} {-| Module : Data.Number.MPFR.Instances.Up@@ -31,13 +31,14 @@ import Data.Ratio --- #if (__GLASGOW_HASKELL__ >= 610) && (__GLASGOW_HASKELL__ < 612)--- import GHC.Integer.Internals--- #elif __GLASGOW_HASKELL__ >= 612--- import GHC.Integer.GMP.Internals--- #endif+#ifdef INTEGER_SIMPLE+--import GHC.Integer.Simple.Internals+#endif+#ifdef INTEGER_GMP+import GHC.Integer.GMP.Internals+import qualified GHC.Exts as E+#endif --- import qualified GHC.Exts as E instance Num MPFR where d + d' = A.add Up (maxPrec d d') d d'@@ -46,10 +47,14 @@ negate d = A.neg Up (getPrec d) d abs d = A.absD Up (getPrec d) d signum = fromInt Up minPrec . fromMaybe (-1) . sgn+#ifdef INTEGER_SIMPLE fromInteger i = fromIntegerA Up (max minPrec $ 1 + bitsInInteger i) i--- fromInteger (S# i) = fromInt Up minPrec (E.I# i)--- fromInteger i@(J# n _) = fromIntegerA Zero (fromIntegral . abs $ E.I# n * bitsPerIntegerLimb) i +#endif+#ifdef INTEGER_GMP+ fromInteger (S# i) = fromInt Up minPrec (E.I# i)+ fromInteger i@(J# n _) = fromIntegerA Zero (fromIntegral . abs $ E.I# n * bitsPerIntegerLimb) i +#endif instance Real MPFR where toRational d = n % 2 ^ e
src/Data/Number/MPFR/Instances/Zero.hs view
@@ -1,4 +1,4 @@--- {-# LANGUAGE MagicHash, CPP #-}+{-# LANGUAGE MagicHash, CPP #-} {-| Module : Data.Number.MPFR.Instances.Zero Description : Instance declarations@@ -31,13 +31,13 @@ import Data.Ratio --- #if (__GLASGOW_HASKELL__ >= 610) && (__GLASGOW_HASKELL__ < 612)--- import GHC.Integer.Internals--- #elif __GLASGOW_HASKELL__ >= 612--- import GHC.Integer.GMP.Internals--- #endif---- import qualified GHC.Exts as E+#ifdef INTEGER_SIMPLE+--import GHC.Integer.Simple.Internals+#endif+#ifdef INTEGER_GMP+import GHC.Integer.GMP.Internals+import qualified GHC.Exts as E+#endif instance Num MPFR where d + d' = A.add Zero (maxPrec d d') d d'@@ -46,10 +46,14 @@ negate d = A.neg Zero (getPrec d) d abs d = A.absD Zero (getPrec d) d signum = fromInt Zero minPrec . fromMaybe (-1) . sgn+#ifdef INTEGER_SIMPLE fromInteger i = fromIntegerA Zero (max minPrec $ 1 + bitsInInteger i) i--- fromInteger (S# i) = fromInt Zero minPrec (E.I# i)--- fromInteger i@(J# n _) = fromIntegerA Zero (fromIntegral . abs $ E.I# n * bitsPerIntegerLimb) i +#endif+#ifdef INTEGER_GMP+ fromInteger (S# i) = fromInt Zero minPrec (E.I# i)+ fromInteger i@(J# n _) = fromIntegerA Zero (fromIntegral . abs $ E.I# n * bitsPerIntegerLimb) i +#endif instance Real MPFR where toRational d = n % 2 ^ e
src/Data/Number/MPFR/Mutable/Internal.hs view
@@ -29,7 +29,7 @@ -- | A mutable MPFR. Currently this is just a newtype wrapped STRef to -- a MPFR but this may change in the future for a more efficient implementation. -- Type argument @s@ is the state variable argument for the @ST@ type.-newtype MMPFR s = MMPFR { run :: STRef s MPFR }+newtype MMPFR s = MMPFR { run :: STRef s MPFR } deriving Eq {-# INLINE unsafeWriteMMPFR #-} -- | Replace the state of the mutable MPFR with a new one. The actual limbs are