packages feed

hmpfr 0.4.0.2 → 0.4.1

raw patch · 5 files changed

+85/−70 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Number.MPFR: digamma :: RoundMode -> Precision -> MPFR -> MPFR
+ Data.Number.MPFR: digamma_ :: RoundMode -> Precision -> MPFR -> (MPFR, Int)
+ Data.Number.MPFR.Mutable: digamma :: MMPFR s -> MMPFR s -> RoundMode -> ST s Int

Files

ChangeLog view
@@ -1,3 +1,5 @@+0.4.1: 2nd Aug 2016: Added support for digamma+0.4.: 11th Jul 2016: Compiles only with ghc 7.10 or newer 0.3.3: 22 Dec 2011: Compiles with both integer-simple and integer-gmp (but mis-behaves with standard integer-gmp). 0.3.2: 28 Feb 2011: Adapted to work with mpfr 3.0.0, now depends on integer-simple. 0.3: 23 Sep 2009: Added mutable interface and removed some modules from the export list.
hmpfr.cabal view
@@ -1,5 +1,5 @@ name:                hmpfr-version:             0.4.0.2+version:             0.4.1 synopsis:            Haskell binding to the MPFR library description:   Haskell binding to the MPFR library.@@ -16,6 +16,7 @@ Stability:           experimental Tested-with:                 GHC==7.10.3+                GHC==8.0.1 author:              Aleš Bizjak, Michal Konečný maintainer:          Michal Konečný <mikkonecny@gmail.com> Homepage:            https://github.com/michalkonecny/hmpfr
src/Data/Number/MPFR/FFIhelper.hsc view
@@ -22,37 +22,37 @@ import Data.Typeable(Typeable)  import Data.Function(on)-    -data RoundMode = Near | Zero | Up | Down | MPFR_RNDNA ++data RoundMode = Near | Zero | Up | Down | MPFR_RNDNA                  deriving (Show, Read)  instance Enum RoundMode where #if MPFR_VERSION_MAJOR == 2-    fromEnum Near        = #{const GMP_RNDN} -    fromEnum Zero        = #{const GMP_RNDZ} -    fromEnum Up          = #{const GMP_RNDU} -    fromEnum Down        = #{const GMP_RNDD} +    fromEnum Near        = #{const GMP_RNDN}+    fromEnum Zero        = #{const GMP_RNDZ}+    fromEnum Up          = #{const GMP_RNDU}+    fromEnum Down        = #{const GMP_RNDD}     fromEnum MPFR_RNDNA   = #{const GMP_RNDNA}-    +     toEnum #{const GMP_RNDN}    = Near     toEnum #{const GMP_RNDZ}    = Zero     toEnum #{const GMP_RNDU}    = Up     toEnum #{const GMP_RNDD}    = Down     toEnum (#{const GMP_RNDNA}) = MPFR_RNDNA #else-    fromEnum Near        = #{const MPFR_RNDN} -    fromEnum Zero        = #{const MPFR_RNDZ} -    fromEnum Up          = #{const MPFR_RNDU} -    fromEnum Down        = #{const MPFR_RNDD} +    fromEnum Near        = #{const MPFR_RNDN}+    fromEnum Zero        = #{const MPFR_RNDZ}+    fromEnum Up          = #{const MPFR_RNDU}+    fromEnum Down        = #{const MPFR_RNDD}     fromEnum MPFR_RNDNA   = #{const MPFR_RNDNA}-    +     toEnum #{const MPFR_RNDN}    = Near     toEnum #{const MPFR_RNDZ}    = Zero     toEnum #{const MPFR_RNDU}    = Up     toEnum #{const MPFR_RNDD}    = Down     toEnum (#{const MPFR_RNDNA}) = MPFR_RNDNA #endif-    toEnum i                    = error $ "RoundMode.toEnum called with illegal argument :" ++ show i +    toEnum i                    = error $ "RoundMode.toEnum called with illegal argument :" ++ show i   data MPFR = MP { precision :: {-# UNPACK #-} !CPrecision,@@ -66,7 +66,7 @@     alignment _ = alignment (undefined :: #{type mpfr_prec_t})     peek = error "MPFR.peek: Not needed and not applicable"     poke p (MP prec s e fp) = do #{poke __mpfr_struct, _mpfr_prec} p prec-                                 #{poke __mpfr_struct, _mpfr_sign} p s +                                 #{poke __mpfr_struct, _mpfr_sign} p s                                  #{poke __mpfr_struct, _mpfr_exp} p e                                  withForeignPtr fp $ \p1 -> #{poke __mpfr_struct, _mpfr_d} p p1 @@ -75,16 +75,16 @@ instance Num Precision where     (Precision w) + (Precision w') = Precision $ w + w'     (Precision w) * (Precision w') = Precision $ w * w'-    (Precision a) - (Precision b) = -        if a >= b -        then Precision (a - b) -        else error $ "instance Precision Num (-): " ++ +    (Precision a) - (Precision b) =+        if a >= b+        then Precision (a - b)+        else error $ "instance Precision Num (-): " ++                        "Operation would result in negative precision."-    negate = error $ "instance Precision Num negate: " ++ +    negate = error $ "instance Precision Num negate: " ++                        "operation would result in negative precision"     abs = id     signum (Precision x) = Precision . signum $ x-    fromInteger i = if i >= 0 +    fromInteger i = if i >= 0                     then Precision . fromInteger $ i                     else error $ "instance Precision Num fromInteger: " ++                              "operation would result  in negative precision"@@ -100,7 +100,7 @@ peekNoLimbPrec      :: Ptr MPFR -> IO (Sign, Exp) peekNoLimbPrec p = do r21 <- #{peek __mpfr_struct, _mpfr_sign} p                       r22 <- #{peek __mpfr_struct, _mpfr_exp} p-                      return (r21, r22)            +                      return (r21, r22)   {-# INLINE peekP #-}@@ -111,12 +111,12 @@                 return (MP r11 r21 r22 fp) {-# INLINE withDummy #-} withDummy     :: Precision -> (Ptr MPFR -> IO CInt) -> IO (MPFR, Int)-withDummy w f = +withDummy w f =     do alloca $ \ptr -> do                       ls <- mpfr_custom_get_size (fromIntegral . runPrec $ w)                       fp <- mallocForeignPtrBytes (fromIntegral ls)                       #{poke __mpfr_struct, _mpfr_prec} ptr (fromIntegral w :: CPrecision)-                      #{poke __mpfr_struct, _mpfr_sign} ptr (1 :: Sign) +                      #{poke __mpfr_struct, _mpfr_sign} ptr (1 :: Sign)                       #{poke __mpfr_struct, _mpfr_exp} ptr (0 :: Exp)                       withForeignPtr fp $ \p1 -> #{poke __mpfr_struct, _mpfr_d} ptr p1                       r2 <- f ptr@@ -126,11 +126,11 @@ {-# INLINE pokeDummy #-} pokeDummy          :: Ptr MPFR -> ForeignPtr Limb -> Precision -> IO () pokeDummy ptr fp p = do #{poke __mpfr_struct, _mpfr_prec} ptr ((fromIntegral . runPrec $ p) :: CPrecision)-                        #{poke __mpfr_struct, _mpfr_sign} ptr (0 :: Sign) +                        #{poke __mpfr_struct, _mpfr_sign} ptr (0 :: Sign)                         #{poke __mpfr_struct, _mpfr_exp} ptr (0 :: Exp)                         withForeignPtr fp $ \p1 -> #{poke __mpfr_struct, _mpfr_d} ptr p1 -bitsPerMPLimb :: Int +bitsPerMPLimb :: Int bitsPerMPLimb = 8 * #size mp_limb_t  bitsPerIntegerLimb :: Int@@ -172,7 +172,7 @@  -------------------- foreign import ccall unsafe "mpfr_get_prec_wrap"-        mpfr_get_prec :: Ptr MPFR -> IO CPrecision +        mpfr_get_prec :: Ptr MPFR -> IO CPrecision  ---------------------------------------------------------------- @@ -222,10 +222,10 @@         mpfr_get_d_2exp :: Ptr CLong -> Ptr MPFR -> CRoundMode -> IO CDouble  -- !!!!!!! next 4 set erange flags-foreign import ccall unsafe "mpfr_get_si" +foreign import ccall unsafe "mpfr_get_si"         mpfr_get_si :: Ptr MPFR -> CRoundMode -> IO CLong -foreign import ccall unsafe "mpfr_get_ui" +foreign import ccall unsafe "mpfr_get_ui"         mpfr_get_ui :: Ptr MPFR -> CRoundMode -> IO CULong  foreign import ccall unsafe "mpfr_get_str"@@ -278,13 +278,13 @@ foreign import ccall unsafe "mpfr_sub"         mpfr_sub :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt -foreign import ccall unsafe "mpfr_ui_sub" +foreign import ccall unsafe "mpfr_ui_sub"         mpfr_ui_sub :: Ptr MPFR -> CULong -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_sub_ui"         mpfr_sub_ui :: Ptr MPFR -> Ptr MPFR -> CULong -> CRoundMode -> IO CInt -foreign import ccall unsafe "mpfr_si_sub" +foreign import ccall unsafe "mpfr_si_sub"         mpfr_si_sub :: Ptr MPFR -> CLong -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_sub_si"@@ -297,7 +297,7 @@         mpfr_d_sub :: Ptr MPFR -> CDouble -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_mul"-        mpfr_mul :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt +        mpfr_mul :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_mul_ui"         mpfr_mul_ui :: Ptr MPFR -> Ptr MPFR -> CULong -> CRoundMode -> IO CInt@@ -345,10 +345,10 @@         mpfr_cbrt :: Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_root"-        mpfr_root :: Ptr MPFR -> Ptr MPFR -> CULong -> CRoundMode -> IO CInt +        mpfr_root :: Ptr MPFR -> Ptr MPFR -> CULong -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_pow"-        mpfr_pow :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt +        mpfr_pow :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_pow_ui"         mpfr_pow_ui :: Ptr MPFR -> Ptr MPFR -> CULong -> CRoundMode -> IO CInt@@ -363,10 +363,10 @@         mpfr_ui_pow :: Ptr MPFR -> CULong -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_neg"-        mpfr_neg :: Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt +        mpfr_neg :: Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_abs_wrap"-        mpfr_abs :: Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt +        mpfr_abs :: Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_dim"         mpfr_dim :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt@@ -422,30 +422,30 @@         mpfr_zero_p :: Ptr MPFR -> IO CInt  foreign import ccall unsafe "mpfr_sgn_wrap"-        mpfr_sgn :: Ptr MPFR -> IO CInt +        mpfr_sgn :: Ptr MPFR -> IO CInt  foreign import ccall unsafe "mpfr_greater_p"         mpfr_greater_p :: Ptr MPFR ->  Ptr MPFR -> IO CInt  foreign import ccall unsafe "mpfr_greaterequal_p"-        mpfr_greaterequal_p :: Ptr MPFR -> Ptr MPFR -> IO CInt +        mpfr_greaterequal_p :: Ptr MPFR -> Ptr MPFR -> IO CInt  foreign import ccall unsafe "mpfr_less_p"-        mpfr_less_p :: Ptr MPFR -> Ptr MPFR -> IO CInt +        mpfr_less_p :: Ptr MPFR -> Ptr MPFR -> IO CInt  foreign import ccall unsafe "mpfr_lessequal_p"-        mpfr_lessequal_p :: Ptr MPFR -> Ptr MPFR -> IO CInt +        mpfr_lessequal_p :: Ptr MPFR -> Ptr MPFR -> IO CInt  foreign import ccall unsafe "mpfr_lessgreater_p"-        mpfr_lessgreater_p :: Ptr MPFR -> Ptr MPFR -> IO CInt +        mpfr_lessgreater_p :: Ptr MPFR -> Ptr MPFR -> IO CInt  foreign import ccall unsafe "mpfr_equal_p"-        mpfr_equal_p :: Ptr MPFR -> Ptr MPFR -> IO CInt +        mpfr_equal_p :: Ptr MPFR -> Ptr MPFR -> IO CInt  foreign import ccall unsafe "mpfr_unordered_p"-        mpfr_unordered_p :: Ptr MPFR -> Ptr MPFR -> IO CInt +        mpfr_unordered_p :: Ptr MPFR -> Ptr MPFR -> IO CInt --- special functions +-- special functions  foreign import ccall unsafe "mpfr_log"         mpfr_log :: Ptr MPFR -> Ptr MPFR ->  CRoundMode -> IO CInt@@ -552,6 +552,9 @@ foreign import ccall unsafe "mpfr_lgamma"         mpfr_lgamma :: Ptr MPFR -> Ptr CInt -> Ptr MPFR ->  CRoundMode -> IO CInt +foreign import ccall unsafe "mpfr_digamma"+        mpfr_digamma :: Ptr MPFR -> Ptr MPFR ->  CRoundMode -> IO CInt+ foreign import ccall unsafe "mpfr_zeta"         mpfr_zeta :: Ptr MPFR -> Ptr MPFR ->  CRoundMode -> IO CInt @@ -583,16 +586,16 @@         mpfr_yn :: Ptr MPFR -> CLong -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_fma"-        mpfr_fma :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  +        mpfr_fma :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_fms"         mpfr_fms :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_agm"-        mpfr_agm :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  +        mpfr_agm :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_hypot"-        mpfr_hypot :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  +        mpfr_hypot :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  -- constants foreign import ccall unsafe "mpfr_const_log2_wrap"@@ -631,7 +634,7 @@  foreign import ccall unsafe "mpfr_trunc_wrap"         mpfr_trunc :: Ptr MPFR -> Ptr MPFR -> IO CInt- + foreign import ccall unsafe "mpfr_rint_ceil"         mpfr_rint_ceil :: Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt @@ -653,10 +656,10 @@ foreign import ccall unsafe "mpfr_fmod"         mpfr_fmod :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt -foreign import ccall unsafe "mpfr_remainder" +foreign import ccall unsafe "mpfr_remainder"         mpfr_remainder :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt -foreign import ccall unsafe "mpfr_remquo" +foreign import ccall unsafe "mpfr_remquo"         mpfr_remquo :: Ptr MPFR -> Ptr CLong -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_integer_p"@@ -696,7 +699,7 @@         mpfr_setsign :: Ptr MPFR -> Ptr MPFR -> CInt -> CRoundMode -> IO CInt  foreign import ccall unsafe "mpfr_copysign_wrap"-        mpfr_copysign :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt +        mpfr_copysign :: Ptr MPFR -> Ptr MPFR -> Ptr MPFR -> CRoundMode -> IO CInt  --------------------------------------------------------------- -- rounding mode related functions@@ -781,7 +784,7 @@  --------------------------------------------------------------- -- custom interface-foreign import ccall unsafe "mpfr_custom_get_size_wrap" +foreign import ccall unsafe "mpfr_custom_get_size_wrap"         mpfr_custom_get_size :: CPrecision -> IO #{type size_t}  foreign import ccall unsafe "mpfr_custom_init_wrap"
src/Data/Number/MPFR/Mutable/Special.hs view
@@ -128,6 +128,9 @@                  (a, b, _) -> (a,b) -} +digamma :: MMPFR s -> MMPFR s -> RoundMode -> ST s Int+digamma = withMutableMPFRS mpfr_digamma+ zeta :: MMPFR s -> MMPFR s -> RoundMode -> ST s Int zeta = withMutableMPFRS mpfr_zeta 
src/Data/Number/MPFR/Special.hs view
@@ -54,7 +54,7 @@  sincos          :: RoundMode                 -> Precision -- ^ precision to compute sin-                -> Precision -- ^ precision to compute cos +                -> Precision -- ^ precision to compute cos                 -> MPFR                 -> (MPFR, MPFR) -- ^ return (sin x, cos x) sincos r p p' d = case sincos_ r p p' d of@@ -83,7 +83,7 @@  sinhcosh          :: RoundMode                   -> Precision -- ^ precision to compute sin-                  -> Precision -- ^ precision to compute cos +                  -> Precision -- ^ precision to compute cos                   -> MPFR                   -> (MPFR, MPFR) -- ^ return (sin x, cos x) sinhcosh r p p' d = case sinhcosh_ r p p' d of@@ -129,9 +129,12 @@ lngamma r p = fst . lngamma_ r p  lgamma       :: RoundMode -> Precision -> MPFR -> (MPFR, Int)-lgamma r p d = case lgamma_ r p d of +lgamma r p d = case lgamma_ r p d of                  (a, b, _) -> (a,b) +digamma     :: RoundMode -> Precision -> MPFR -> MPFR+digamma r p = fst . digamma_ r p+ zeta     :: RoundMode -> Precision -> MPFR -> MPFR zeta r p = fst . zeta_ r p @@ -226,17 +229,17 @@  sincos_ :: RoundMode          -> Precision -- ^ precision to compute sin-         -> Precision -- ^ precision to compute cos +         -> Precision -- ^ precision to compute cos          -> MPFR          -> (MPFR, MPFR, Int)-sincos_ r p p' d = unsafePerformIO go +sincos_ r p p' d = unsafePerformIO go     where go = do ls <- mpfr_custom_get_size (fromIntegral p)                   fp <- mallocForeignPtrBytes (fromIntegral ls)                   ls' <- mpfr_custom_get_size (fromIntegral p')                   fp' <- mallocForeignPtrBytes (fromIntegral ls')-                  alloca $ \p1 -> do +                  alloca $ \p1 -> do                     pokeDummy p1 fp (fromIntegral ls)-                    alloca $ \p2 -> do +                    alloca $ \p2 -> do                       pokeDummy p2 fp' (fromIntegral ls')                       with d $ \p3 -> do                         r3 <- mpfr_sin_cos p1 p2 p3 ((fromIntegral . fromEnum) r)@@ -254,7 +257,7 @@ atan_ r p d = withMPFR r p d mpfr_atan  atan2_ :: RoundMode -> Precision -> MPFR -> MPFR -> (MPFR, Int)-atan2_ r p d d' = withMPFRsBA r p d d' mpfr_atan2 +atan2_ r p d d' = withMPFRsBA r p d d' mpfr_atan2  sinh_       :: RoundMode -> Precision -> MPFR -> (MPFR, Int) sinh_ r p d = withMPFR r p d mpfr_sinh@@ -267,17 +270,17 @@  sinhcosh_          :: RoundMode                    -> Precision -- ^ precision to compute sinh-                   -> Precision -- ^ precision to compute cosh +                   -> Precision -- ^ precision to compute cosh                    -> MPFR                    -> (MPFR, MPFR, Int)-sinhcosh_ r p p' d = unsafePerformIO go +sinhcosh_ r p p' d = unsafePerformIO go     where go = do ls <- mpfr_custom_get_size (fromIntegral p)                   fp <- mallocForeignPtrBytes (fromIntegral ls)                   ls' <- mpfr_custom_get_size (fromIntegral p')                   fp' <- mallocForeignPtrBytes (fromIntegral ls')-                  alloca $ \p1 -> do +                  alloca $ \p1 -> do                     pokeDummy p1 fp (fromIntegral ls)-                    alloca $ \p2 -> do +                    alloca $ \p2 -> do                       pokeDummy p2 fp' (fromIntegral ls')                       with d $ \p3 -> do                         r3 <- mpfr_sinh_cosh p1 p2 p3 ((fromIntegral . fromEnum) r)@@ -336,7 +339,10 @@                         r2 <- peek p3                         r1 <- peekP p1 fp                         return (r1, fromIntegral r2, fromIntegral r3)-                    ++digamma_       :: RoundMode -> Precision -> MPFR -> (MPFR, Int)+digamma_ r p d = withMPFR r p d mpfr_digamma+ zeta_       :: RoundMode -> Precision -> MPFR -> (MPFR, Int) zeta_ r p d = withMPFR r p d mpfr_zeta @@ -369,19 +375,19 @@  fma_                 :: RoundMode -> Precision -> MPFR -> MPFR -> MPFR -> (MPFR, Int) fma_ r p mp1 mp2 mp3 = unsafePerformIO go-    where go = withDummy p $ \p1 -> -                 with mp1 $ \p2 -> +    where go = withDummy p $ \p1 ->+                 with mp1 $ \p2 ->                    with mp2 $ \p3 ->                      with mp3 $ \p4 ->-                       mpfr_fma p1 p2 p3 p4 ((fromIntegral . fromEnum) r) +                       mpfr_fma p1 p2 p3 p4 ((fromIntegral . fromEnum) r)  fms_                 :: RoundMode -> Precision -> MPFR -> MPFR -> MPFR -> (MPFR, Int) fms_ r p mp1 mp2 mp3 = unsafePerformIO go     where go = withDummy p $ \p1 ->-                 with mp1 $ \p2 -> +                 with mp1 $ \p2 ->                    with mp2 $ \p3 ->                      with mp3 $ \p4 ->-                       mpfr_fms p1 p2 p3 p4 ((fromIntegral . fromEnum) r) +                       mpfr_fms p1 p2 p3 p4 ((fromIntegral . fromEnum) r)  agm_           :: RoundMode -> Precision -> MPFR -> MPFR -> (MPFR,Int) agm_ r p d1 d2 =  withMPFRsBA r p d1 d2 mpfr_agm