summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-07-28 18:35:00 +0000
committerAlberto Ruiz <aruiz@um.es>2007-07-28 18:35:00 +0000
commit8731b5e093e0014472e870bf5166e2d074d206c1 (patch)
tree76c49133991b25e6587d617185236a8c789e7023
parent774924233c87a20c31a3232cbd01d9bf5170a951 (diff)
GSL.Special.Exp.hs
-rw-r--r--HSSL.cabal2
-rw-r--r--lib/GSL/Special.hs8
-rw-r--r--lib/GSL/Special/Exp.hs129
-rw-r--r--lib/GSL/Special/auto.hs11
-rw-r--r--lib/GSL/Special/exp.h18
5 files changed, 162 insertions, 6 deletions
diff --git a/HSSL.cabal b/HSSL.cabal
index 9859548..8b6f2a6 100644
--- a/HSSL.cabal
+++ b/HSSL.cabal
@@ -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)
9Stability : provisional 9Stability : provisional
10Portability : uses ffi 10Portability : uses ffi
11 11
12Wrappers for a few special functions. 12Wrappers 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.
18module GSL.Special ( 18module 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)
25where 24where
26 25
@@ -28,6 +27,7 @@ import Foreign
28import GSL.Special.Internal 27import GSL.Special.Internal
29import GSL.Special.Gamma 28import GSL.Special.Gamma
30import GSL.Special.Erf 29import GSL.Special.Erf
30import GSL.Special.Exp
31import GSL.Special.Airy 31import 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{- |
3Module : GSL.Special.Exp
4Copyright : (c) Alberto Ruiz 2006
5License : GPL-style
6Maintainer : Alberto Ruiz (aruiz at um dot es)
7Stability : provisional
8Portability : uses ffi
9
10Wrappers for selected functions described at:
11
12<http://www.gnu.org/software/gsl/manual/html_node/Exponential-Functions.html>
13
14-}
15------------------------------------------------------------
16
17module 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
38import Foreign(Ptr)
39import GSL.Special.Internal
40
41-- | wrapper for int gsl_sf_exp_e(double x,gsl_sf_result* result);
42exp_e :: Double -> (Double,Double)
43exp_e x = createSFR "exp_e" $ gsl_sf_exp_e x
44foreign 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);
47exp :: Double -> Double
48exp = gsl_sf_exp
49foreign 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);
52exp_e10_e :: Double -> (Double,Int,Double)
53exp_e10_e x = createSFR_E10 "exp_e10_e" $ gsl_sf_exp_e10_e x
54foreign 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);
57exp_mult_e :: Double -> Double -> (Double,Double)
58exp_mult_e x y = createSFR "exp_mult_e" $ gsl_sf_exp_mult_e x y
59foreign 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);
62exp_mult :: Double -> Double -> Double
63exp_mult = gsl_sf_exp_mult
64foreign 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);
67exp_mult_e10_e :: Double -> Double -> (Double,Int,Double)
68exp_mult_e10_e x y = createSFR_E10 "exp_mult_e10_e" $ gsl_sf_exp_mult_e10_e x y
69foreign 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);
72expm1_e :: Double -> (Double,Double)
73expm1_e x = createSFR "expm1_e" $ gsl_sf_expm1_e x
74foreign 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);
77expm1 :: Double -> Double
78expm1 = gsl_sf_expm1
79foreign 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);
82exprel_e :: Double -> (Double,Double)
83exprel_e x = createSFR "exprel_e" $ gsl_sf_exprel_e x
84foreign 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);
87exprel :: Double -> Double
88exprel = gsl_sf_exprel
89foreign 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);
92exprel_2_e :: Double -> (Double,Double)
93exprel_2_e x = createSFR "exprel_2_e" $ gsl_sf_exprel_2_e x
94foreign 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);
97exprel_2 :: Double -> Double
98exprel_2 = gsl_sf_exprel_2
99foreign 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);
102exprel_n_e :: Int -> Double -> (Double,Double)
103exprel_n_e n x = createSFR "exprel_n_e" $ gsl_sf_exprel_n_e n x
104foreign 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);
107exprel_n :: Int -> Double -> Double
108exprel_n = gsl_sf_exprel_n
109foreign 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);
112exp_err_e :: Double -> Double -> (Double,Double)
113exp_err_e x dx = createSFR "exp_err_e" $ gsl_sf_exp_err_e x dx
114foreign 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);
117exp_err_e10_e :: Double -> Double -> (Double,Int,Double)
118exp_err_e10_e x dx = createSFR_E10 "exp_err_e10_e" $ gsl_sf_exp_err_e10_e x dx
119foreign 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);
122exp_mult_err_e :: Double -> Double -> Double -> Double -> (Double,Double)
123exp_mult_err_e x dx y dy = createSFR "exp_mult_err_e" $ gsl_sf_exp_mult_err_e x dx y dy
124foreign 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);
127exp_mult_err_e10_e :: Double -> Double -> Double -> Double -> (Double,Int,Double)
128exp_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
129foreign 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
40fixC s = rep ("gsl_mode_t","int") $ rep ("gsl_sf_result","double") $ s 41fixC s = rep ("gsl_mode_t","int") $ rep ("gsl_sf_result","double") $ rep ("gsl_sf_result_e10","double") $ s
41 42
42main = do 43main = 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
156pure (Header _ _ args) | fst (last args) == Pointer "gsl_sf_result" = False 157pure (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
159showC (Header t n args) = showCt t ++ " " ++ n ++ "(" ++ (concat $ intersperse "," $ map showCa args) ++ ");" 161showC (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
170showHt (Normal (s:ss)) = toUpper s : ss 172showHt (Normal (s:ss)) = toUpper s : ss
171showHt (Pointer "gsl_sf_result") = "Ptr Double" 173showHt (Pointer "gsl_sf_result") = "Ptr Double"
174showHt (Pointer "gsl_sf_result_e10") = "Ptr ()"
172showHt (Pointer (s:ss)) = "Ptr "++toUpper s : ss 175showHt (Pointer (s:ss)) = "Ptr "++toUpper s : ss
173 176
174showHa (t,a) = showHt t 177showHa (t,a) = showHt t
@@ -179,6 +182,7 @@ fixmd1 = rep ("Gsl_mode_t","Precision")
179fixmd2 = rep ("mode"," (precCode mode)") 182fixmd2 = rep ("mode"," (precCode mode)")
180 183
181boiler h@(Header t n args) | fst (last args) == Pointer "gsl_sf_result" = boilerResult h 184boiler 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
198boilerResultE10 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
194boilerBasic h@(Header t n args) = 203boilerBasic 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 @@
1int gsl_sf_exp_e(double x,double* result);
2double gsl_sf_exp(double x);
3int gsl_sf_exp_e10_e(double x,double* result);
4int gsl_sf_exp_mult_e(double x,double y,double* result);
5double gsl_sf_exp_mult(double x,double y);
6int gsl_sf_exp_mult_e10_e(double x,double y,double* result);
7int gsl_sf_expm1_e(double x,double* result);
8double gsl_sf_expm1(double x);
9int gsl_sf_exprel_e(double x,double* result);
10double gsl_sf_exprel(double x);
11int gsl_sf_exprel_2_e(double x,double* result);
12double gsl_sf_exprel_2(double x);
13int gsl_sf_exprel_n_e(int n,double x,double* result);
14double gsl_sf_exprel_n(int n,double x);
15int gsl_sf_exp_err_e(double x,double dx,double* result);
16int gsl_sf_exp_err_e10_e(double x,double dx,double* result);
17int gsl_sf_exp_mult_err_e(double x,double dx,double y,double dy,double* result);
18int gsl_sf_exp_mult_err_e10_e(double x,double dx,double y,double dy,double* result);