diff options
Diffstat (limited to 'lib/Numeric/GSL/Special/Internal.hs')
-rw-r--r-- | lib/Numeric/GSL/Special/Internal.hs | 68 |
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 | {- | | ||
4 | Module : Numeric.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 Numeric.GSL.Special.Internal ( | ||
19 | createSFR, | ||
20 | createSFR_E10, | ||
21 | Precision(..), | ||
22 | Gsl_mode_t, | ||
23 | Size_t, | ||
24 | precCode | ||
25 | ) | ||
26 | where | ||
27 | |||
28 | import Foreign | ||
29 | import Data.Packed.Internal(check,(//)) | ||
30 | |||
31 | |||
32 | data Precision = PrecDouble | PrecSingle | PrecApprox | ||
33 | |||
34 | precCode :: Precision -> Int | ||
35 | precCode PrecDouble = 0 | ||
36 | precCode PrecSingle = 1 | ||
37 | precCode PrecApprox = 2 | ||
38 | |||
39 | type Gsl_mode_t = Int | ||
40 | |||
41 | type Size_t = Int | ||
42 | |||
43 | ---------------------------------------------------------------- | ||
44 | -- | access to a sf_result | ||
45 | createSFR :: Storable a => String -> (Ptr a -> IO Int) -> (a, a) | ||
46 | createSFR 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 | ||
58 | createSFR_E10 :: (Storable t2, Storable t3, Storable t1) => String -> (Ptr a -> IO Int) -> (t1, t2, t3) | ||
59 | createSFR_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) | ||