module Numeric.GSL.Special.Internal (
createSFR,
create2SFR,
createSFR_E10,
Precision(..),
Gsl_mode_t,
Size_t,
precCode
)
where
import Foreign.Storable
import Foreign.Ptr
import Foreign.Marshal
import System.IO.Unsafe(unsafePerformIO)
import Data.Packed.Development(check,(//))
import Foreign.C.Types
data Precision = PrecDouble | PrecSingle | PrecApprox
precCode :: Precision -> Int
precCode PrecDouble = 0
precCode PrecSingle = 1
precCode PrecApprox = 2
type Gsl_mode_t = Int
type Size_t = CSize
data Gsl_sf_result = SF Double Double
deriving (Show)
instance Storable Gsl_sf_result where
sizeOf _ = (16)
alignment _ = 8
peek ptr = do
val <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
err <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
return (SF val err)
poke ptr (SF val err) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr val
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr err
data Gsl_sf_result_e10 = SFE Double Double CInt
deriving (Show)
instance Storable Gsl_sf_result_e10 where
sizeOf _ = (24)
alignment _ = 8
peek ptr = do
val <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
err <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
e10 <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
return (SFE val err e10)
poke ptr (SFE val err e10) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr val
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr err
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr e10
createSFR :: String -> (Ptr a -> IO CInt) -> (Double, Double)
createSFR s f = unsafePerformIO $ do
p <- malloc :: IO (Ptr Gsl_sf_result)
f (castPtr p) // check s
SF val err <- peek p
free p
return (val,err)
create2SFR :: String -> (Ptr a -> Ptr a -> IO CInt) -> ((Double, Double),(Double, Double))
create2SFR s f = unsafePerformIO $ do
p1 <- malloc :: IO (Ptr Gsl_sf_result)
p2 <- malloc :: IO (Ptr Gsl_sf_result)
f (castPtr p1) (castPtr p2) // check s
SF val1 err1 <- peek p1
SF val2 err2 <- peek p2
free p1
free p2
return ((val1,err1),(val2,err2))
createSFR_E10 :: String -> (Ptr a -> IO CInt) -> (Double, Int, Double)
createSFR_E10 s f = unsafePerformIO $ do
p <- malloc :: IO (Ptr Gsl_sf_result_e10)
f (castPtr p) // check s
SFE val err expo <- peek p
free p
return (val, fromIntegral expo,err)