From 8731b5e093e0014472e870bf5166e2d074d206c1 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sat, 28 Jul 2007 18:35:00 +0000 Subject: GSL.Special.Exp.hs --- lib/GSL/Special.hs | 8 +-- lib/GSL/Special/Exp.hs | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/GSL/Special/auto.hs | 11 ++++- lib/GSL/Special/exp.h | 18 +++++++ 4 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 lib/GSL/Special/Exp.hs create mode 100644 lib/GSL/Special/exp.h (limited to 'lib/GSL') 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) Stability : provisional Portability : uses ffi -Wrappers for a few special functions. +Wrappers for selected special functions. -} @@ -18,9 +18,8 @@ Wrappers for a few special functions. module GSL.Special ( module GSL.Special.Airy, module GSL.Special.Erf, - module GSL.Special.Gamma, - bessel_J0_e, - exp_e10_e + module GSL.Special.Exp, + module GSL.Special.Gamma ) where @@ -28,6 +27,7 @@ import Foreign import GSL.Special.Internal import GSL.Special.Gamma import GSL.Special.Erf +import GSL.Special.Exp import GSL.Special.Airy -------------------- 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 @@ +------------------------------------------------------------ +{- | +Module : GSL.Special.Exp +Copyright : (c) Alberto Ruiz 2006 +License : GPL-style +Maintainer : Alberto Ruiz (aruiz at um dot es) +Stability : provisional +Portability : uses ffi + +Wrappers for selected functions described at: + + + +-} +------------------------------------------------------------ + +module GSL.Special.Exp( + exp_e +, GSL.Special.Exp.exp +, exp_e10_e +, exp_mult_e +, exp_mult +, exp_mult_e10_e +, expm1_e +, expm1 +, exprel_e +, exprel +, exprel_2_e +, exprel_2 +, exprel_n_e +, exprel_n +, exp_err_e +, exp_err_e10_e +, exp_mult_err_e +, exp_mult_err_e10_e +) where + +import Foreign(Ptr) +import GSL.Special.Internal + +-- | wrapper for int gsl_sf_exp_e(double x,gsl_sf_result* result); +exp_e :: Double -> (Double,Double) +exp_e x = createSFR "exp_e" $ gsl_sf_exp_e x +foreign import ccall "exp.h gsl_sf_exp_e" gsl_sf_exp_e :: Double -> Ptr Double -> IO(Int) + +-- | wrapper for double gsl_sf_exp(double x); +exp :: Double -> Double +exp = gsl_sf_exp +foreign import ccall "exp.h gsl_sf_exp" gsl_sf_exp :: Double -> Double + +-- | wrapper for int gsl_sf_exp_e10_e(double x,gsl_sf_result_e10* result); +exp_e10_e :: Double -> (Double,Int,Double) +exp_e10_e x = createSFR_E10 "exp_e10_e" $ gsl_sf_exp_e10_e x +foreign import ccall "exp.h gsl_sf_exp_e10_e" gsl_sf_exp_e10_e :: Double -> Ptr () -> IO(Int) + +-- | wrapper for int gsl_sf_exp_mult_e(double x,double y,gsl_sf_result* result); +exp_mult_e :: Double -> Double -> (Double,Double) +exp_mult_e x y = createSFR "exp_mult_e" $ gsl_sf_exp_mult_e x y +foreign import ccall "exp.h gsl_sf_exp_mult_e" gsl_sf_exp_mult_e :: Double -> Double -> Ptr Double -> IO(Int) + +-- | wrapper for double gsl_sf_exp_mult(double x,double y); +exp_mult :: Double -> Double -> Double +exp_mult = gsl_sf_exp_mult +foreign import ccall "exp.h gsl_sf_exp_mult" gsl_sf_exp_mult :: Double -> Double -> Double + +-- | wrapper for int gsl_sf_exp_mult_e10_e(double x,double y,gsl_sf_result_e10* result); +exp_mult_e10_e :: Double -> Double -> (Double,Int,Double) +exp_mult_e10_e x y = createSFR_E10 "exp_mult_e10_e" $ gsl_sf_exp_mult_e10_e x y +foreign import ccall "exp.h gsl_sf_exp_mult_e10_e" gsl_sf_exp_mult_e10_e :: Double -> Double -> Ptr () -> IO(Int) + +-- | wrapper for int gsl_sf_expm1_e(double x,gsl_sf_result* result); +expm1_e :: Double -> (Double,Double) +expm1_e x = createSFR "expm1_e" $ gsl_sf_expm1_e x +foreign import ccall "exp.h gsl_sf_expm1_e" gsl_sf_expm1_e :: Double -> Ptr Double -> IO(Int) + +-- | wrapper for double gsl_sf_expm1(double x); +expm1 :: Double -> Double +expm1 = gsl_sf_expm1 +foreign import ccall "exp.h gsl_sf_expm1" gsl_sf_expm1 :: Double -> Double + +-- | wrapper for int gsl_sf_exprel_e(double x,gsl_sf_result* result); +exprel_e :: Double -> (Double,Double) +exprel_e x = createSFR "exprel_e" $ gsl_sf_exprel_e x +foreign import ccall "exp.h gsl_sf_exprel_e" gsl_sf_exprel_e :: Double -> Ptr Double -> IO(Int) + +-- | wrapper for double gsl_sf_exprel(double x); +exprel :: Double -> Double +exprel = gsl_sf_exprel +foreign import ccall "exp.h gsl_sf_exprel" gsl_sf_exprel :: Double -> Double + +-- | wrapper for int gsl_sf_exprel_2_e(double x,gsl_sf_result* result); +exprel_2_e :: Double -> (Double,Double) +exprel_2_e x = createSFR "exprel_2_e" $ gsl_sf_exprel_2_e x +foreign import ccall "exp.h gsl_sf_exprel_2_e" gsl_sf_exprel_2_e :: Double -> Ptr Double -> IO(Int) + +-- | wrapper for double gsl_sf_exprel_2(double x); +exprel_2 :: Double -> Double +exprel_2 = gsl_sf_exprel_2 +foreign import ccall "exp.h gsl_sf_exprel_2" gsl_sf_exprel_2 :: Double -> Double + +-- | wrapper for int gsl_sf_exprel_n_e(int n,double x,gsl_sf_result* result); +exprel_n_e :: Int -> Double -> (Double,Double) +exprel_n_e n x = createSFR "exprel_n_e" $ gsl_sf_exprel_n_e n x +foreign import ccall "exp.h gsl_sf_exprel_n_e" gsl_sf_exprel_n_e :: Int -> Double -> Ptr Double -> IO(Int) + +-- | wrapper for double gsl_sf_exprel_n(int n,double x); +exprel_n :: Int -> Double -> Double +exprel_n = gsl_sf_exprel_n +foreign import ccall "exp.h gsl_sf_exprel_n" gsl_sf_exprel_n :: Int -> Double -> Double + +-- | wrapper for int gsl_sf_exp_err_e(double x,double dx,gsl_sf_result* result); +exp_err_e :: Double -> Double -> (Double,Double) +exp_err_e x dx = createSFR "exp_err_e" $ gsl_sf_exp_err_e x dx +foreign import ccall "exp.h gsl_sf_exp_err_e" gsl_sf_exp_err_e :: Double -> Double -> Ptr Double -> IO(Int) + +-- | wrapper for int gsl_sf_exp_err_e10_e(double x,double dx,gsl_sf_result_e10* result); +exp_err_e10_e :: Double -> Double -> (Double,Int,Double) +exp_err_e10_e x dx = createSFR_E10 "exp_err_e10_e" $ gsl_sf_exp_err_e10_e x dx +foreign import ccall "exp.h gsl_sf_exp_err_e10_e" gsl_sf_exp_err_e10_e :: Double -> Double -> Ptr () -> IO(Int) + +-- | wrapper for int gsl_sf_exp_mult_err_e(double x,double dx,double y,double dy,gsl_sf_result* result); +exp_mult_err_e :: Double -> Double -> Double -> Double -> (Double,Double) +exp_mult_err_e x dx y dy = createSFR "exp_mult_err_e" $ gsl_sf_exp_mult_err_e x dx y dy +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) + +-- | wrapper for int gsl_sf_exp_mult_err_e10_e(double x,double dx,double y,double dy,gsl_sf_result_e10* result); +exp_mult_err_e10_e :: Double -> Double -> Double -> Double -> (Double,Int,Double) +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 +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 where ok ((Normal s),_) | s `elem` ["double","float","int","gsl_mode_t"] = True ok _ = False kn ((Pointer "gsl_sf_result"),_) = True + kn ((Pointer "gsl_sf_result_e10"),_) = True kn _ = False -fixC s = rep ("gsl_mode_t","int") $ rep ("gsl_sf_result","double") $ s +fixC s = rep ("gsl_mode_t","int") $ rep ("gsl_sf_result","double") $ rep ("gsl_sf_result_e10","double") $ s main = do args <- getArgs @@ -154,6 +155,7 @@ t2 = do return (Pointer t,n) pure (Header _ _ args) | fst (last args) == Pointer "gsl_sf_result" = False + | fst (last args) == Pointer "gsl_sf_result_e10" = False | otherwise = True 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++ showHt (Normal (s:ss)) = toUpper s : ss showHt (Pointer "gsl_sf_result") = "Ptr Double" +showHt (Pointer "gsl_sf_result_e10") = "Ptr ()" showHt (Pointer (s:ss)) = "Ptr "++toUpper s : ss showHa (t,a) = showHt t @@ -179,6 +182,7 @@ fixmd1 = rep ("Gsl_mode_t","Precision") fixmd2 = rep ("mode"," (precCode mode)") boiler h@(Header t n args) | fst (last args) == Pointer "gsl_sf_result" = boilerResult h + | fst (last args) == Pointer "gsl_sf_result_e10" = boilerResultE10 h | any isMode args = boilerMode h | otherwise = boilerBasic h @@ -191,6 +195,11 @@ boilerResult h@(Header t n args) = drop 7 n ++ " "++(unwords (map snd (init args)))++ " = createSFR \""++ drop 7 n ++"\" $ " ++ n ++ " "++(fixmd2 $ unwords (map snd (init args))) +boilerResultE10 h@(Header t n args) = + drop 7 n++" :: "++ (fixmd1 $ concat $ intersperse" -> "$ map showHa (init args)) ++" -> " ++ "(Double,Int,Double)\n" ++ + drop 7 n ++ " "++(unwords (map snd (init args)))++ + " = createSFR_E10 \""++ drop 7 n ++"\" $ " ++ n ++ " "++(fixmd2 $ unwords (map snd (init args))) + boilerBasic h@(Header t n args) = drop 7 n++" :: "++ (fixmd1 $ concat $ intersperse" -> "$map showHa args) ++" -> " ++showHt t ++ "\n" ++ 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 @@ +int gsl_sf_exp_e(double x,double* result); +double gsl_sf_exp(double x); +int gsl_sf_exp_e10_e(double x,double* result); +int gsl_sf_exp_mult_e(double x,double y,double* result); +double gsl_sf_exp_mult(double x,double y); +int gsl_sf_exp_mult_e10_e(double x,double y,double* result); +int gsl_sf_expm1_e(double x,double* result); +double gsl_sf_expm1(double x); +int gsl_sf_exprel_e(double x,double* result); +double gsl_sf_exprel(double x); +int gsl_sf_exprel_2_e(double x,double* result); +double gsl_sf_exprel_2(double x); +int gsl_sf_exprel_n_e(int n,double x,double* result); +double gsl_sf_exprel_n(int n,double x); +int gsl_sf_exp_err_e(double x,double dx,double* result); +int gsl_sf_exp_err_e10_e(double x,double dx,double* result); +int gsl_sf_exp_mult_err_e(double x,double dx,double y,double dy,double* result); +int gsl_sf_exp_mult_err_e10_e(double x,double dx,double y,double dy,double* result); -- cgit v1.2.3