summaryrefslogtreecommitdiff
path: root/lib/Numeric/GSL/Special/Internal.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/GSL/Special/Internal.hs')
-rw-r--r--lib/Numeric/GSL/Special/Internal.hs68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/Numeric/GSL/Special/Internal.hs b/lib/Numeric/GSL/Special/Internal.hs
new file mode 100644
index 0000000..a08809b
--- /dev/null
+++ b/lib/Numeric/GSL/Special/Internal.hs
@@ -0,0 +1,68 @@
1{-# OPTIONS #-}
2-----------------------------------------------------------------------------
3{- |
4Module : Numeric.GSL.Special.Internal
5Copyright : (c) Alberto Ruiz 2007
6License : GPL-style
7
8Maintainer : Alberto Ruiz (aruiz at um dot es)
9Stability : provisional
10Portability : uses ffi
11
12Support for Special functions.
13
14<http://www.gnu.org/software/gsl/manual/html_node/Special-Functions.html#Special-Functions>
15-}
16-----------------------------------------------------------------------------
17
18module Numeric.GSL.Special.Internal (
19 createSFR,
20 createSFR_E10,
21 Precision(..),
22 Gsl_mode_t,
23 Size_t,
24 precCode
25)
26where
27
28import Foreign
29import Data.Packed.Internal(check,(//))
30
31
32data Precision = PrecDouble | PrecSingle | PrecApprox
33
34precCode :: Precision -> Int
35precCode PrecDouble = 0
36precCode PrecSingle = 1
37precCode PrecApprox = 2
38
39type Gsl_mode_t = Int
40
41type Size_t = Int
42
43----------------------------------------------------------------
44-- | access to a sf_result
45createSFR :: Storable a => String -> (Ptr a -> IO Int) -> (a, a)
46createSFR s f = unsafePerformIO $ do
47 p <- mallocArray 2
48 f p // check s []
49 [val,err] <- peekArray 2 p
50 free p
51 return (val,err)
52
53
54---------------------------------------------------------------------
55-- the sf_result_e10 contains two doubles and the exponent
56
57-- | acces to sf_result_e10
58createSFR_E10 :: (Storable t2, Storable t3, Storable t1) => String -> (Ptr a -> IO Int) -> (t1, t2, t3)
59createSFR_E10 s f = unsafePerformIO $ do
60 let sd = sizeOf (0::Double)
61 let si = sizeOf (0::Int)
62 p <- mallocBytes (2*sd + si)
63 f p // check s []
64 val <- peekByteOff p 0
65 err <- peekByteOff p sd
66 expo <- peekByteOff p (2*sd)
67 free p
68 return (val,expo,err)