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