diff options
Diffstat (limited to 'lib/GSL/Special.hs')
-rw-r--r-- | lib/GSL/Special.hs | 48 |
1 files changed, 9 insertions, 39 deletions
diff --git a/lib/GSL/Special.hs b/lib/GSL/Special.hs index fec96eb..01aec2b 100644 --- a/lib/GSL/Special.hs +++ b/lib/GSL/Special.hs | |||
@@ -9,25 +9,27 @@ Maintainer : Alberto Ruiz (aruiz at um dot es) | |||
9 | Stability : provisional | 9 | Stability : provisional |
10 | Portability : uses ffi | 10 | Portability : uses ffi |
11 | 11 | ||
12 | Special functions. | 12 | Wrappers for a few special functions. |
13 | 13 | ||
14 | <http://www.gnu.org/software/gsl/manual/html_node/Special-Functions.html#Special-Functions> | 14 | <http://www.gnu.org/software/gsl/manual/html_node/Special-Functions.html#Special-Functions> |
15 | -} | 15 | -} |
16 | ----------------------------------------------------------------------------- | 16 | ----------------------------------------------------------------------------- |
17 | 17 | ||
18 | module GSL.Special ( | 18 | module GSL.Special ( |
19 | erf, | 19 | module GSL.Special.Airy, |
20 | erf_Z, | 20 | module GSL.Special.Erf, |
21 | module GSL.Special.Gamma, | ||
21 | bessel_J0_e, | 22 | bessel_J0_e, |
22 | exp_e10_e, | 23 | exp_e10_e |
23 | gamma | ||
24 | ) | 24 | ) |
25 | where | 25 | where |
26 | 26 | ||
27 | import Foreign | 27 | import Foreign |
28 | import Data.Packed.Internal.Common(check,(//)) | 28 | import GSL.Special.Internal |
29 | import GSL.Special.Gamma | ||
30 | import GSL.Special.Erf | ||
31 | import GSL.Special.Airy | ||
29 | 32 | ||
30 | ---------------------------------------------------------------- | ||
31 | -------------------- simple functions -------------------------- | 33 | -------------------- simple functions -------------------------- |
32 | 34 | ||
33 | {- | The error function (/gsl_sf_erf/), defined as 2\/ \\sqrt \\pi * \int\_0\^t \\exp -t\^2 dt. | 35 | {- | The error function (/gsl_sf_erf/), defined as 2\/ \\sqrt \\pi * \int\_0\^t \\exp -t\^2 dt. |
@@ -46,24 +48,6 @@ foreign import ccall "gsl-aux.h gsl_sf_erf" erf :: Double -> Double | |||
46 | -} | 48 | -} |
47 | foreign import ccall "gsl-aux.h gsl_sf_erf_Z" erf_Z :: Double -> Double | 49 | foreign import ccall "gsl-aux.h gsl_sf_erf_Z" erf_Z :: Double -> Double |
48 | 50 | ||
49 | {- | The gamma function (/gsl_sf_gamma/), described in <http://www.gnu.org/software/gsl/manual/html_node/Gamma-Functions.html> | ||
50 | |||
51 | >> gamma 5 | ||
52 | >24.0 | ||
53 | |||
54 | -} | ||
55 | foreign import ccall "gsl-aux.h gsl_sf_gamma" gamma :: Double -> Double | ||
56 | |||
57 | ---------------------------------------------------------------- | ||
58 | -- the sf_result struct is equivalent to an array of two doubles | ||
59 | |||
60 | createSFR s f = unsafePerformIO $ do | ||
61 | p <- mallocArray 2 | ||
62 | f p // check "createSFR" [] | ||
63 | [val,err] <- peekArray 2 p | ||
64 | free p | ||
65 | return (val,err) | ||
66 | |||
67 | -------------------- functions returning sf_result ------------- | 51 | -------------------- functions returning sf_result ------------- |
68 | 52 | ||
69 | {- | The regular cylindrical Bessel function of zeroth order, J_0(x). This is | 53 | {- | The regular cylindrical Bessel function of zeroth order, J_0(x). This is |
@@ -78,20 +62,6 @@ bessel_J0_e :: Double -> (Double,Double) | |||
78 | bessel_J0_e x = createSFR "bessel_J0_e" (gsl_sf_bessel_J0_e x) | 62 | bessel_J0_e x = createSFR "bessel_J0_e" (gsl_sf_bessel_J0_e x) |
79 | foreign import ccall "gsl-aux.h gsl_sf_bessel_J0_e" gsl_sf_bessel_J0_e :: Double -> Ptr Double -> IO Int | 63 | foreign import ccall "gsl-aux.h gsl_sf_bessel_J0_e" gsl_sf_bessel_J0_e :: Double -> Ptr Double -> IO Int |
80 | 64 | ||
81 | --------------------------------------------------------------------- | ||
82 | -- the sf_result_e10 contains two doubles and the exponent | ||
83 | |||
84 | createSFR_E10 s f = unsafePerformIO $ do | ||
85 | let sd = sizeOf (0::Double) | ||
86 | let si = sizeOf (0::Int) | ||
87 | p <- mallocBytes (2*sd + si) | ||
88 | f p // check "createSFR_E10" [] | ||
89 | val <- peekByteOff p 0 | ||
90 | err <- peekByteOff p sd | ||
91 | expo <- peekByteOff p (2*sd) | ||
92 | free p | ||
93 | return (val,expo,err) | ||
94 | |||
95 | -------------------- functions returning sf_result_e10 ------------- | 65 | -------------------- functions returning sf_result_e10 ------------- |
96 | 66 | ||
97 | {- | (From the GSL manual) \"This function computes the exponential \exp(x) using the @gsl_sf_result_e10@ type to return a result with extended range. This function may be useful if the value of \exp(x) would overflow the numeric range of double\". | 67 | {- | (From the GSL manual) \"This function computes the exponential \exp(x) using the @gsl_sf_result_e10@ type to return a result with extended range. This function may be useful if the value of \exp(x) would overflow the numeric range of double\". |