diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-07-28 18:35:00 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-07-28 18:35:00 +0000 |
commit | 8731b5e093e0014472e870bf5166e2d074d206c1 (patch) | |
tree | 76c49133991b25e6587d617185236a8c789e7023 | |
parent | 774924233c87a20c31a3232cbd01d9bf5170a951 (diff) |
GSL.Special.Exp.hs
-rw-r--r-- | HSSL.cabal | 2 | ||||
-rw-r--r-- | lib/GSL/Special.hs | 8 | ||||
-rw-r--r-- | lib/GSL/Special/Exp.hs | 129 | ||||
-rw-r--r-- | lib/GSL/Special/auto.hs | 11 | ||||
-rw-r--r-- | lib/GSL/Special/exp.h | 18 |
5 files changed, 162 insertions, 6 deletions
@@ -30,7 +30,7 @@ Exposed-modules: Data.Packed.Internal, | |||
30 | GSL.Differentiation, GSL.Integration, | 30 | GSL.Differentiation, GSL.Integration, |
31 | GSL.Special, GSL.Special.Internal, | 31 | GSL.Special, GSL.Special.Internal, |
32 | GSL.Special.Gamma, GSL.Special.Erf, | 32 | GSL.Special.Gamma, GSL.Special.Erf, |
33 | GSL.Special.Airy, | 33 | GSL.Special.Airy, GSL.Special.Exp, |
34 | GSL.Fourier, | 34 | GSL.Fourier, |
35 | GSL.Polynomials, | 35 | GSL.Polynomials, |
36 | GSL.Minimization, | 36 | GSL.Minimization, |
diff --git a/lib/GSL/Special.hs b/lib/GSL/Special.hs index 01aec2b..6786dc5 100644 --- a/lib/GSL/Special.hs +++ b/lib/GSL/Special.hs | |||
@@ -9,7 +9,7 @@ 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 | Wrappers for a few special functions. | 12 | Wrappers for selected 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 | -} |
@@ -18,9 +18,8 @@ Wrappers for a few special functions. | |||
18 | module GSL.Special ( | 18 | module GSL.Special ( |
19 | module GSL.Special.Airy, | 19 | module GSL.Special.Airy, |
20 | module GSL.Special.Erf, | 20 | module GSL.Special.Erf, |
21 | module GSL.Special.Gamma, | 21 | module GSL.Special.Exp, |
22 | bessel_J0_e, | 22 | module GSL.Special.Gamma |
23 | exp_e10_e | ||
24 | ) | 23 | ) |
25 | where | 24 | where |
26 | 25 | ||
@@ -28,6 +27,7 @@ import Foreign | |||
28 | import GSL.Special.Internal | 27 | import GSL.Special.Internal |
29 | import GSL.Special.Gamma | 28 | import GSL.Special.Gamma |
30 | import GSL.Special.Erf | 29 | import GSL.Special.Erf |
30 | import GSL.Special.Exp | ||
31 | import GSL.Special.Airy | 31 | import GSL.Special.Airy |
32 | 32 | ||
33 | -------------------- simple functions -------------------------- | 33 | -------------------- simple functions -------------------------- |
diff --git a/lib/GSL/Special/Exp.hs b/lib/GSL/Special/Exp.hs new file mode 100644 index 0000000..8c3e5b8 --- /dev/null +++ b/lib/GSL/Special/Exp.hs | |||
@@ -0,0 +1,129 @@ | |||
1 | ------------------------------------------------------------ | ||
2 | {- | | ||
3 | Module : GSL.Special.Exp | ||
4 | Copyright : (c) Alberto Ruiz 2006 | ||
5 | License : GPL-style | ||
6 | Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
7 | Stability : provisional | ||
8 | Portability : uses ffi | ||
9 | |||
10 | Wrappers for selected functions described at: | ||
11 | |||
12 | <http://www.gnu.org/software/gsl/manual/html_node/Exponential-Functions.html> | ||
13 | |||
14 | -} | ||
15 | ------------------------------------------------------------ | ||
16 | |||
17 | module GSL.Special.Exp( | ||
18 | exp_e | ||
19 | , GSL.Special.Exp.exp | ||
20 | , exp_e10_e | ||
21 | , exp_mult_e | ||
22 | , exp_mult | ||
23 | , exp_mult_e10_e | ||
24 | , expm1_e | ||
25 | , expm1 | ||
26 | , exprel_e | ||
27 | , exprel | ||
28 | , exprel_2_e | ||
29 | , exprel_2 | ||
30 | , exprel_n_e | ||
31 | , exprel_n | ||
32 | , exp_err_e | ||
33 | , exp_err_e10_e | ||
34 | , exp_mult_err_e | ||
35 | , exp_mult_err_e10_e | ||
36 | ) where | ||
37 | |||
38 | import Foreign(Ptr) | ||
39 | import GSL.Special.Internal | ||
40 | |||
41 | -- | wrapper for int gsl_sf_exp_e(double x,gsl_sf_result* result); | ||
42 | exp_e :: Double -> (Double,Double) | ||
43 | exp_e x = createSFR "exp_e" $ gsl_sf_exp_e x | ||
44 | foreign import ccall "exp.h gsl_sf_exp_e" gsl_sf_exp_e :: Double -> Ptr Double -> IO(Int) | ||
45 | |||
46 | -- | wrapper for double gsl_sf_exp(double x); | ||
47 | exp :: Double -> Double | ||
48 | exp = gsl_sf_exp | ||
49 | foreign import ccall "exp.h gsl_sf_exp" gsl_sf_exp :: Double -> Double | ||
50 | |||
51 | -- | wrapper for int gsl_sf_exp_e10_e(double x,gsl_sf_result_e10* result); | ||
52 | exp_e10_e :: Double -> (Double,Int,Double) | ||
53 | exp_e10_e x = createSFR_E10 "exp_e10_e" $ gsl_sf_exp_e10_e x | ||
54 | foreign import ccall "exp.h gsl_sf_exp_e10_e" gsl_sf_exp_e10_e :: Double -> Ptr () -> IO(Int) | ||
55 | |||
56 | -- | wrapper for int gsl_sf_exp_mult_e(double x,double y,gsl_sf_result* result); | ||
57 | exp_mult_e :: Double -> Double -> (Double,Double) | ||
58 | exp_mult_e x y = createSFR "exp_mult_e" $ gsl_sf_exp_mult_e x y | ||
59 | foreign import ccall "exp.h gsl_sf_exp_mult_e" gsl_sf_exp_mult_e :: Double -> Double -> Ptr Double -> IO(Int) | ||
60 | |||
61 | -- | wrapper for double gsl_sf_exp_mult(double x,double y); | ||
62 | exp_mult :: Double -> Double -> Double | ||
63 | exp_mult = gsl_sf_exp_mult | ||
64 | foreign import ccall "exp.h gsl_sf_exp_mult" gsl_sf_exp_mult :: Double -> Double -> Double | ||
65 | |||
66 | -- | wrapper for int gsl_sf_exp_mult_e10_e(double x,double y,gsl_sf_result_e10* result); | ||
67 | exp_mult_e10_e :: Double -> Double -> (Double,Int,Double) | ||
68 | exp_mult_e10_e x y = createSFR_E10 "exp_mult_e10_e" $ gsl_sf_exp_mult_e10_e x y | ||
69 | foreign import ccall "exp.h gsl_sf_exp_mult_e10_e" gsl_sf_exp_mult_e10_e :: Double -> Double -> Ptr () -> IO(Int) | ||
70 | |||
71 | -- | wrapper for int gsl_sf_expm1_e(double x,gsl_sf_result* result); | ||
72 | expm1_e :: Double -> (Double,Double) | ||
73 | expm1_e x = createSFR "expm1_e" $ gsl_sf_expm1_e x | ||
74 | foreign import ccall "exp.h gsl_sf_expm1_e" gsl_sf_expm1_e :: Double -> Ptr Double -> IO(Int) | ||
75 | |||
76 | -- | wrapper for double gsl_sf_expm1(double x); | ||
77 | expm1 :: Double -> Double | ||
78 | expm1 = gsl_sf_expm1 | ||
79 | foreign import ccall "exp.h gsl_sf_expm1" gsl_sf_expm1 :: Double -> Double | ||
80 | |||
81 | -- | wrapper for int gsl_sf_exprel_e(double x,gsl_sf_result* result); | ||
82 | exprel_e :: Double -> (Double,Double) | ||
83 | exprel_e x = createSFR "exprel_e" $ gsl_sf_exprel_e x | ||
84 | foreign import ccall "exp.h gsl_sf_exprel_e" gsl_sf_exprel_e :: Double -> Ptr Double -> IO(Int) | ||
85 | |||
86 | -- | wrapper for double gsl_sf_exprel(double x); | ||
87 | exprel :: Double -> Double | ||
88 | exprel = gsl_sf_exprel | ||
89 | foreign import ccall "exp.h gsl_sf_exprel" gsl_sf_exprel :: Double -> Double | ||
90 | |||
91 | -- | wrapper for int gsl_sf_exprel_2_e(double x,gsl_sf_result* result); | ||
92 | exprel_2_e :: Double -> (Double,Double) | ||
93 | exprel_2_e x = createSFR "exprel_2_e" $ gsl_sf_exprel_2_e x | ||
94 | foreign import ccall "exp.h gsl_sf_exprel_2_e" gsl_sf_exprel_2_e :: Double -> Ptr Double -> IO(Int) | ||
95 | |||
96 | -- | wrapper for double gsl_sf_exprel_2(double x); | ||
97 | exprel_2 :: Double -> Double | ||
98 | exprel_2 = gsl_sf_exprel_2 | ||
99 | foreign import ccall "exp.h gsl_sf_exprel_2" gsl_sf_exprel_2 :: Double -> Double | ||
100 | |||
101 | -- | wrapper for int gsl_sf_exprel_n_e(int n,double x,gsl_sf_result* result); | ||
102 | exprel_n_e :: Int -> Double -> (Double,Double) | ||
103 | exprel_n_e n x = createSFR "exprel_n_e" $ gsl_sf_exprel_n_e n x | ||
104 | foreign import ccall "exp.h gsl_sf_exprel_n_e" gsl_sf_exprel_n_e :: Int -> Double -> Ptr Double -> IO(Int) | ||
105 | |||
106 | -- | wrapper for double gsl_sf_exprel_n(int n,double x); | ||
107 | exprel_n :: Int -> Double -> Double | ||
108 | exprel_n = gsl_sf_exprel_n | ||
109 | foreign import ccall "exp.h gsl_sf_exprel_n" gsl_sf_exprel_n :: Int -> Double -> Double | ||
110 | |||
111 | -- | wrapper for int gsl_sf_exp_err_e(double x,double dx,gsl_sf_result* result); | ||
112 | exp_err_e :: Double -> Double -> (Double,Double) | ||
113 | exp_err_e x dx = createSFR "exp_err_e" $ gsl_sf_exp_err_e x dx | ||
114 | foreign import ccall "exp.h gsl_sf_exp_err_e" gsl_sf_exp_err_e :: Double -> Double -> Ptr Double -> IO(Int) | ||
115 | |||
116 | -- | wrapper for int gsl_sf_exp_err_e10_e(double x,double dx,gsl_sf_result_e10* result); | ||
117 | exp_err_e10_e :: Double -> Double -> (Double,Int,Double) | ||
118 | exp_err_e10_e x dx = createSFR_E10 "exp_err_e10_e" $ gsl_sf_exp_err_e10_e x dx | ||
119 | foreign import ccall "exp.h gsl_sf_exp_err_e10_e" gsl_sf_exp_err_e10_e :: Double -> Double -> Ptr () -> IO(Int) | ||
120 | |||
121 | -- | wrapper for int gsl_sf_exp_mult_err_e(double x,double dx,double y,double dy,gsl_sf_result* result); | ||
122 | exp_mult_err_e :: Double -> Double -> Double -> Double -> (Double,Double) | ||
123 | exp_mult_err_e x dx y dy = createSFR "exp_mult_err_e" $ gsl_sf_exp_mult_err_e x dx y dy | ||
124 | foreign import ccall "exp.h gsl_sf_exp_mult_err_e" gsl_sf_exp_mult_err_e :: Double -> Double -> Double -> Double -> Ptr Double -> IO(Int) | ||
125 | |||
126 | -- | wrapper for int gsl_sf_exp_mult_err_e10_e(double x,double dx,double y,double dy,gsl_sf_result_e10* result); | ||
127 | exp_mult_err_e10_e :: Double -> Double -> Double -> Double -> (Double,Int,Double) | ||
128 | exp_mult_err_e10_e x dx y dy = createSFR_E10 "exp_mult_err_e10_e" $ gsl_sf_exp_mult_err_e10_e x dx y dy | ||
129 | foreign import ccall "exp.h gsl_sf_exp_mult_err_e10_e" gsl_sf_exp_mult_err_e10_e :: Double -> Double -> Double -> Double -> Ptr () -> IO(Int) | ||
diff --git a/lib/GSL/Special/auto.hs b/lib/GSL/Special/auto.hs index f047bcb..42829bb 100644 --- a/lib/GSL/Special/auto.hs +++ b/lib/GSL/Special/auto.hs | |||
@@ -33,11 +33,12 @@ safe (Header _ _ args) = all ok args | |||
33 | where ok ((Normal s),_) | s `elem` ["double","float","int","gsl_mode_t"] = True | 33 | where ok ((Normal s),_) | s `elem` ["double","float","int","gsl_mode_t"] = True |
34 | ok _ = False | 34 | ok _ = False |
35 | kn ((Pointer "gsl_sf_result"),_) = True | 35 | kn ((Pointer "gsl_sf_result"),_) = True |
36 | kn ((Pointer "gsl_sf_result_e10"),_) = True | ||
36 | kn _ = False | 37 | kn _ = False |
37 | 38 | ||
38 | 39 | ||
39 | 40 | ||
40 | fixC s = rep ("gsl_mode_t","int") $ rep ("gsl_sf_result","double") $ s | 41 | fixC s = rep ("gsl_mode_t","int") $ rep ("gsl_sf_result","double") $ rep ("gsl_sf_result_e10","double") $ s |
41 | 42 | ||
42 | main = do | 43 | main = do |
43 | args <- getArgs | 44 | args <- getArgs |
@@ -154,6 +155,7 @@ t2 = do | |||
154 | return (Pointer t,n) | 155 | return (Pointer t,n) |
155 | 156 | ||
156 | pure (Header _ _ args) | fst (last args) == Pointer "gsl_sf_result" = False | 157 | pure (Header _ _ args) | fst (last args) == Pointer "gsl_sf_result" = False |
158 | | fst (last args) == Pointer "gsl_sf_result_e10" = False | ||
157 | | otherwise = True | 159 | | otherwise = True |
158 | 160 | ||
159 | showC (Header t n args) = showCt t ++ " " ++ n ++ "(" ++ (concat $ intersperse "," $ map showCa args) ++ ");" | 161 | showC (Header t n args) = showCt t ++ " " ++ n ++ "(" ++ (concat $ intersperse "," $ map showCa args) ++ ");" |
@@ -169,6 +171,7 @@ showH hc h@(Header t n args) = "foreign import ccall \""++hc++" "++n++"\" "++n++ | |||
169 | 171 | ||
170 | showHt (Normal (s:ss)) = toUpper s : ss | 172 | showHt (Normal (s:ss)) = toUpper s : ss |
171 | showHt (Pointer "gsl_sf_result") = "Ptr Double" | 173 | showHt (Pointer "gsl_sf_result") = "Ptr Double" |
174 | showHt (Pointer "gsl_sf_result_e10") = "Ptr ()" | ||
172 | showHt (Pointer (s:ss)) = "Ptr "++toUpper s : ss | 175 | showHt (Pointer (s:ss)) = "Ptr "++toUpper s : ss |
173 | 176 | ||
174 | showHa (t,a) = showHt t | 177 | showHa (t,a) = showHt t |
@@ -179,6 +182,7 @@ fixmd1 = rep ("Gsl_mode_t","Precision") | |||
179 | fixmd2 = rep ("mode"," (precCode mode)") | 182 | fixmd2 = rep ("mode"," (precCode mode)") |
180 | 183 | ||
181 | boiler h@(Header t n args) | fst (last args) == Pointer "gsl_sf_result" = boilerResult h | 184 | boiler h@(Header t n args) | fst (last args) == Pointer "gsl_sf_result" = boilerResult h |
185 | | fst (last args) == Pointer "gsl_sf_result_e10" = boilerResultE10 h | ||
182 | | any isMode args = boilerMode h | 186 | | any isMode args = boilerMode h |
183 | | otherwise = boilerBasic h | 187 | | otherwise = boilerBasic h |
184 | 188 | ||
@@ -191,6 +195,11 @@ boilerResult h@(Header t n args) = | |||
191 | drop 7 n ++ " "++(unwords (map snd (init args)))++ | 195 | drop 7 n ++ " "++(unwords (map snd (init args)))++ |
192 | " = createSFR \""++ drop 7 n ++"\" $ " ++ n ++ " "++(fixmd2 $ unwords (map snd (init args))) | 196 | " = createSFR \""++ drop 7 n ++"\" $ " ++ n ++ " "++(fixmd2 $ unwords (map snd (init args))) |
193 | 197 | ||
198 | boilerResultE10 h@(Header t n args) = | ||
199 | drop 7 n++" :: "++ (fixmd1 $ concat $ intersperse" -> "$ map showHa (init args)) ++" -> " ++ "(Double,Int,Double)\n" ++ | ||
200 | drop 7 n ++ " "++(unwords (map snd (init args)))++ | ||
201 | " = createSFR_E10 \""++ drop 7 n ++"\" $ " ++ n ++ " "++(fixmd2 $ unwords (map snd (init args))) | ||
202 | |||
194 | boilerBasic h@(Header t n args) = | 203 | boilerBasic h@(Header t n args) = |
195 | drop 7 n++" :: "++ (fixmd1 $ concat $ intersperse" -> "$map showHa args) ++" -> " ++showHt t ++ "\n" ++ | 204 | drop 7 n++" :: "++ (fixmd1 $ concat $ intersperse" -> "$map showHa args) ++" -> " ++showHt t ++ "\n" ++ |
196 | drop 7 n ++ " = " ++fixmd2 n | 205 | drop 7 n ++ " = " ++fixmd2 n |
diff --git a/lib/GSL/Special/exp.h b/lib/GSL/Special/exp.h new file mode 100644 index 0000000..20062f0 --- /dev/null +++ b/lib/GSL/Special/exp.h | |||
@@ -0,0 +1,18 @@ | |||
1 | int gsl_sf_exp_e(double x,double* result); | ||
2 | double gsl_sf_exp(double x); | ||
3 | int gsl_sf_exp_e10_e(double x,double* result); | ||
4 | int gsl_sf_exp_mult_e(double x,double y,double* result); | ||
5 | double gsl_sf_exp_mult(double x,double y); | ||
6 | int gsl_sf_exp_mult_e10_e(double x,double y,double* result); | ||
7 | int gsl_sf_expm1_e(double x,double* result); | ||
8 | double gsl_sf_expm1(double x); | ||
9 | int gsl_sf_exprel_e(double x,double* result); | ||
10 | double gsl_sf_exprel(double x); | ||
11 | int gsl_sf_exprel_2_e(double x,double* result); | ||
12 | double gsl_sf_exprel_2(double x); | ||
13 | int gsl_sf_exprel_n_e(int n,double x,double* result); | ||
14 | double gsl_sf_exprel_n(int n,double x); | ||
15 | int gsl_sf_exp_err_e(double x,double dx,double* result); | ||
16 | int gsl_sf_exp_err_e10_e(double x,double dx,double* result); | ||
17 | int gsl_sf_exp_mult_err_e(double x,double dx,double y,double dy,double* result); | ||
18 | int gsl_sf_exp_mult_err_e10_e(double x,double dx,double y,double dy,double* result); | ||