hmpfr 0.3.3.5 → 0.4.0
raw patch · 8 files changed
+131/−157 lines, 8 filesdep ~basedep ~integer-gmp
Dependency ranges changed: base, integer-gmp
Files
- README +0/−3
- README.md +1/−0
- hmpfr.cabal +22/−46
- src/Data/Number/MPFR/Instances/Down.hs +17/−17
- src/Data/Number/MPFR/Instances/Near.hs +16/−16
- src/Data/Number/MPFR/Instances/Up.hs +16/−16
- src/Data/Number/MPFR/Instances/Zero.hs +16/−16
- src/Data/Number/MPFR/Internal.hs +43/−43
− README
@@ -1,3 +0,0 @@-Haskell MPFR binding.--If you find bugs or have any questions please write to <ales.bizjak0@gmail.com>.
+ README.md view
@@ -0,0 +1,1 @@+Haskell MPFR binding
hmpfr.cabal view
@@ -1,70 +1,48 @@ name: hmpfr-version: 0.3.3.5+version: 0.4.0 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 features infrequent but serious errors/- /with a ghc that has been compiled with the default integer-gmp./ - /When using ghc, it is recommended to use one compiled with a modified integer-gmp,/- /as described at/ - .- <http://code.google.com/p/hmpfr/wiki/GHCWithRenamedGMP>- .- /or/- /with integer-simple, as described at/- .- <http://code.google.com/p/hmpfr/wiki/GHCWithoutGMP>- .- /There is a hope that at some point future versions of ghc will not need any modification for/- /hmpfr to work with them correctly./- .- 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.+description:+ Haskell binding to the MPFR library.+ .+ 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,- GHC==7.2.2,- GHC==7.4.1+ GHC==7.10.3 author: Aleš Bizjak, Michal Konečný maintainer: Michal Konečný <mikkonecny@gmail.com>-Homepage: http://code.google.com/p/hmpfr/+Homepage: https://github.com/michalkonecny/hmpfr build-type: Simple cabal-version: >= 1.6 Extra-source-files: demo/Demo.hs -Data-files: README- dict.txt- ChangeLog+Data-files:+ README.md+ 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: release-0.3.3.5-+ type: git+ location: https://github.com/michalkonecny/hmpfr 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+ build-Depends: base >= 4.8 && < 5 if flag(use-integer-simple) build-Depends: integer-simple cpp-options: -DINTEGER_SIMPLE else- build-Depends: integer-gmp+ build-Depends: integer-gmp >= 1.0 && < 1.1 cpp-options: -DINTEGER_GMP Other-modules: Data.Number.MPFR.FFIhelper@@ -75,7 +53,7 @@ Data.Number.MPFR.Mutable.Special Data.Number.MPFR.Mutable.Integer Data.Number.MPFR.Mutable.Misc- + Data.Number.MPFR.Assignment Data.Number.MPFR.Conversion Data.Number.MPFR.Arithmetic@@ -92,10 +70,9 @@ Data.Number.MPFR Data.Number.MPFR.Mutable- + build-tools: hsc2hs GHC-options: -Wall -fno-warn-orphans- GHC-prof-options: -prof -auto hs-source-dirs: src include-dirs: cbits includes: mpfr.h@@ -103,4 +80,3 @@ c-sources: cbits/chsmpfr.c extra-libraries: mpfr-
src/Data/Number/MPFR/Instances/Down.hs view
@@ -10,8 +10,8 @@ Portability : non-portable This module defines instances 'Num', 'Real', 'Fractional', 'Floating' and 'RealFrac' of 'MPFR'.- Operations are rounded with 'RoundMode' 'Down' and computed with maximum precision of two - operands or with the precision of the operand. + Operations are rounded with 'RoundMode' 'Down' and computed with maximum precision of two+ operands or with the precision of the operand. -} @@ -31,13 +31,13 @@ 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+-- #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@@ -47,14 +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 = +-- #ifdef INTEGER_SIMPLE+ fromInteger i = fromIntegerA Down (max minPrec $ 1 + bitsInInteger i) 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+-- #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@@ -73,7 +73,7 @@ pi = S.pi Down 53 exp d = S.exp Down (getPrec d) d log d = S.log Down (getPrec d) d- sqrt d = A.sqrt Down (getPrec d) d + sqrt d = A.sqrt Down (getPrec d) d (**) d d' = A.pow Down (maxPrec d d') d d' logBase d d' = Prelude.log d' / Prelude.log d sin d = S.sin Down (getPrec d) d
src/Data/Number/MPFR/Instances/Near.hs view
@@ -10,7 +10,7 @@ Portability : non-portable This module defines instances 'Num', 'Real', 'Fractional', 'Floating' and 'RealFrac' of 'MPFR'.- Operations are rounded with 'RoundMode' 'Near' and computed with maximum precision of two + Operations are rounded with 'RoundMode' 'Near' and computed with maximum precision of two operands or with the precision of the operand. -} @@ -30,13 +30,13 @@ 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+-- #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,14 +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 = +-- #ifdef INTEGER_SIMPLE+ fromInteger i = fromIntegerA Near (max minPrec $ 1 + bitsInInteger i) 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+-- #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@@ -71,7 +71,7 @@ pi = S.pi Near 53 exp d = S.exp Near (getPrec d) d log d = S.log Near (getPrec d) d- sqrt d = A.sqrt Near (getPrec d) d + sqrt d = A.sqrt Near (getPrec d) d (**) d d' = A.pow Near (maxPrec d d') d d' logBase d d' = Prelude.log d' / Prelude.log d sin d = S.sin Near (getPrec d) d
src/Data/Number/MPFR/Instances/Up.hs view
@@ -11,7 +11,7 @@ Portability : non-portable This module defines instances 'Num', 'Real', 'Fractional', 'Floating' and 'RealFrac' of 'MPFR'.- Operations are rounded with 'RoundMode' 'Up' and computed with maximum precision of two + Operations are rounded with 'RoundMode' 'Up' and computed with maximum precision of two operands or with the precision of the operand. -} @@ -31,13 +31,13 @@ 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+-- #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@@ -47,14 +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 = +-- #ifdef INTEGER_SIMPLE+ fromInteger i = fromIntegerA Up (max minPrec $ 1 + bitsInInteger i) 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+-- #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@@ -73,7 +73,7 @@ pi = S.pi Up 53 exp d = S.exp Up (getPrec d) d log d = S.log Up (getPrec d) d- sqrt d = A.sqrt Up (getPrec d) d + sqrt d = A.sqrt Up (getPrec d) d (**) d d' = A.pow Up (maxPrec d d') d d' logBase d d' = Prelude.log d' / Prelude.log d sin d = S.sin Up (getPrec d) d
src/Data/Number/MPFR/Instances/Zero.hs view
@@ -10,7 +10,7 @@ Portability : non-portable This module defines instances 'Num', 'Real', 'Fractional', 'Floating' and 'RealFrac' of 'MPFR'.- Operations are rounded with 'RoundMode' 'Zero' and computed with maximum precision of two + Operations are rounded with 'RoundMode' 'Zero' and computed with maximum precision of two operands or with the precision of the operand. -} @@ -31,13 +31,13 @@ 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+-- #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,14 +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 = +-- #ifdef INTEGER_SIMPLE+ fromInteger i = fromIntegerA Zero (max minPrec $ 1 + bitsInInteger i) 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+-- #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@@ -72,7 +72,7 @@ pi = S.pi Zero 53 exp d = S.exp Zero (getPrec d) d log d = S.log Zero (getPrec d) d- sqrt d = A.sqrt Zero (getPrec d) d + sqrt d = A.sqrt Zero (getPrec d) d (**) d d' = A.pow Zero (maxPrec d d') d d' logBase d d' = Prelude.log d' / Prelude.log d sin d = S.sin Zero (getPrec d) d
src/Data/Number/MPFR/Internal.hs view
@@ -1,10 +1,10 @@ {-# LANGUAGE BangPatterns #-} module Data.Number.MPFR.Internal (- module Data.Number.MPFR.FFIhelper, + module Data.Number.MPFR.FFIhelper, withMPFRsBA, withMPFRBAui, withMPFRBAiu, withMPFRBAd,- withMPFRBAsi, withMPFRBAis, withMPFRBAd', - withMPFRB, withMPFRP, withMPFR, withMPFRBB, withMPFRC, + withMPFRBAsi, withMPFRBAis, withMPFRBAd',+ withMPFRB, withMPFRP, withMPFR, withMPFRBB, withMPFRC, withMPFRF, withMPFRUI, withMPFRR, checkPrec, getMantissa', unsafePerformIO, peek, Ptr, nullPtr, mallocForeignPtrBytes, with, withForeignPtr, CInt, CLong, CULong, withCString, peekCString, alloca,@@ -22,7 +22,7 @@ import Data.Bits(shiftL) -import Data.Word(Word)+-- import Data.Word(Word) -- these are helper functions, only for internal use {-# INLINE withMPFRsBA #-}@@ -30,98 +30,98 @@ -> (Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt) -> (MPFR, Int) withMPFRsBA r p !mp1 !mp2 f = unsafePerformIO go- where go = withDummy p $ \p1 -> - with mp1 $ \p2 -> - with mp2 $ \p3 -> + where go = withDummy p $ \p1 ->+ with mp1 $ \p2 ->+ with mp2 $ \p3 -> f p1 p2 p3 ((fromIntegral . fromEnum) r)- + {-# INLINE withMPFRBAui #-} withMPFRBAui :: RoundMode -> Precision -> MPFR -> CULong -> (Ptr MPFR -> Ptr MPFR -> CULong -> CRoundMode -> IO CInt)- -> (MPFR, Int) + -> (MPFR, Int) withMPFRBAui r p !mp1 d f = unsafePerformIO go- where go = withDummy p $ \p1 -> - with mp1 $ \p2 -> + where go = withDummy p $ \p1 ->+ with mp1 $ \p2 -> f p1 p2 d ((fromIntegral . fromEnum) r)- + {-# INLINE withMPFRBAsi #-} withMPFRBAsi :: RoundMode -> Precision -> MPFR -> CLong -> (Ptr MPFR -> Ptr MPFR -> CLong -> CRoundMode -> IO CInt) -> (MPFR, Int)-withMPFRBAsi r p !mp1 d f = unsafePerformIO go - where go = withDummy p $ \ p1 -> - with mp1 $ \ p2 -> +withMPFRBAsi r p !mp1 d f = unsafePerformIO go+ where go = withDummy p $ \ p1 ->+ with mp1 $ \ p2 -> f p1 p2 d ((fromIntegral . fromEnum) r)- + {-# INLINE withMPFRBAiu #-} withMPFRBAiu :: RoundMode -> Precision -> CULong -> MPFR -> (Ptr MPFR -> CULong -> Ptr MPFR -> CRoundMode -> IO CInt)- -> (MPFR, Int) -withMPFRBAiu r p d !mp1 f = unsafePerformIO go - where go = withDummy p $ \p1 -> - with mp1 $ \p2 -> + -> (MPFR, Int)+withMPFRBAiu r p d !mp1 f = unsafePerformIO go+ where go = withDummy p $ \p1 ->+ with mp1 $ \p2 -> f p1 d p2 ((fromIntegral . fromEnum) r)- + {-# INLINE withMPFRBAis #-} withMPFRBAis :: RoundMode -> Precision -> CLong -> MPFR -> (Ptr MPFR -> CLong -> Ptr MPFR -> CRoundMode -> IO CInt)- -> (MPFR, Int) + -> (MPFR, Int) withMPFRBAis r p d !mp1 f = unsafePerformIO go where go = withDummy p $ \p1 ->- with mp1 $ \p2 -> + with mp1 $ \p2 -> f p1 d p2 ((fromIntegral . fromEnum) r) {-# INLINE withMPFRBAd #-} withMPFRBAd :: RoundMode -> Precision -> MPFR -> CDouble -> (Ptr MPFR -> Ptr MPFR -> CDouble -> CRoundMode -> IO CInt) -> (MPFR, Int)-withMPFRBAd r p !mp1 d f = unsafePerformIO go +withMPFRBAd r p !mp1 d f = unsafePerformIO go where go = withDummy p $ \ p1 -> with mp1 $ \ p2 -> f p1 p2 d ((fromIntegral . fromEnum) r)- + {-# INLINE withMPFRBAd' #-} withMPFRBAd' :: RoundMode -> Precision -> CDouble -> MPFR -> (Ptr MPFR -> CDouble -> Ptr MPFR -> CRoundMode -> IO CInt)- -> (MPFR, Int) -withMPFRBAd' r p d !mp1 f = unsafePerformIO go + -> (MPFR, Int)+withMPFRBAd' r p d !mp1 f = unsafePerformIO go where go = withDummy p $ \p1 -> with mp1 $ \p2 -> f p1 d p2 ((fromIntegral . fromEnum) r) - + {-# INLINE withMPFRB #-}-withMPFRB :: MPFR -> (Ptr MPFR -> IO CInt) -> CInt +withMPFRB :: MPFR -> (Ptr MPFR -> IO CInt) -> CInt withMPFRB !mp1 f = unsafePerformIO go where go = with mp1 f -withMPFRP :: MPFR -> (Ptr MPFR -> IO CPrecision) -> CPrecision +withMPFRP :: MPFR -> (Ptr MPFR -> IO CPrecision) -> CPrecision withMPFRP !mp1 f = unsafePerformIO go where go = with mp1 f {-# INLINE withMPFR #-}-withMPFR :: RoundMode -> Precision -> MPFR - -> (Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt) +withMPFR :: RoundMode -> Precision -> MPFR+ -> (Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt) -> (MPFR, Int)-withMPFR r p !mp1 f = unsafePerformIO go +withMPFR r p !mp1 f = unsafePerformIO go where go = withDummy p $ \p1 -> with mp1 $ \p2 -> f p1 p2 ((fromIntegral . fromEnum) r)- + {-# INLINE withMPFRBB #-}-withMPFRBB :: MPFR -> MPFR - -> (Ptr MPFR -> Ptr MPFR -> IO CInt) - -> CInt +withMPFRBB :: MPFR -> MPFR+ -> (Ptr MPFR -> Ptr MPFR -> IO CInt)+ -> CInt withMPFRBB !mp1 !mp2 f = unsafePerformIO go where go = with mp1 $ with mp2 . f- + {-# INLINE withMPFRC #-} withMPFRC :: RoundMode -> Precision -> (Ptr MPFR -> CRoundMode -> IO CInt) -> (MPFR, Int) withMPFRC r p f = unsafePerformIO go where go = withDummy p $ \p1 -> f p1 ((fromIntegral . fromEnum) r)- + withMPFRF :: MPFR -> RoundMode -> (Ptr MPFR -> CRoundMode -> IO CInt) -> Int@@ -132,10 +132,10 @@ withMPFRUI :: RoundMode -> Precision -> Word -> (Ptr MPFR -> CULong -> CRoundMode -> IO CInt) -> (MPFR, Int)-withMPFRUI r p d f = unsafePerformIO go +withMPFRUI r p d f = unsafePerformIO go where go = withDummy p $ \p1 -> f p1 (fromIntegral d) ((fromIntegral . fromEnum) r)- + {-# INLINE withMPFRR #-} withMPFRR :: Precision -> MPFR -> (Ptr MPFR -> Ptr MPFR -> IO CInt)@@ -143,14 +143,14 @@ withMPFRR p !d f = unsafePerformIO go where go = withDummy p $ with d . f - + {-# INLINE checkPrec #-} checkPrec :: Precision -> Precision checkPrec = max minPrec getMantissa' :: MPFR -> [Limb] getMantissa' (MP p _ _ p1) = unsafePerformIO go- where go = withForeignPtr p1 $ + where go = withForeignPtr p1 $ peekArray (Prelude.ceiling ((fromIntegral p ::Double) / fromIntegral bitsPerMPLimb)) minPrec :: Precision