module Data.Number.Erf(Erf(..)) where
import Foreign.C
foreign import ccall "erf" c_erf :: CDouble -> CDouble
foreign import ccall "erfc" c_erfc :: CDouble -> CDouble
foreign import ccall "erff" c_erff :: CFloat -> CFloat
foreign import ccall "erfcf" c_erfcf :: CFloat -> CFloat
class (Floating a) => Erf a where
erf :: a -> a
erfc :: a -> a
erfcx :: a -> a
normcdf :: a -> a
erf x = 1 erfc x
erfc x = 2 * normcdf (x * sqrt 2)
erfcx x = exp (x*x) * erfc x
normcdf x = erfc(x / sqrt 2) / 2
instance Erf Double where
erf = realToFrac . c_erf . realToFrac
erfc = realToFrac . c_erfc . realToFrac
instance Erf Float where
erf = realToFrac . c_erff . realToFrac
erfc = realToFrac . c_erfcf . realToFrac