module Linear.Epsilon
( Epsilon(..)
) where
import Data.Complex (Complex, magnitude)
import Foreign.C.Types (CFloat, CDouble)
class Num a => Epsilon a where
nearZero :: a -> Bool
instance Epsilon Float where
nearZero :: Float -> Bool
nearZero Float
a = forall a. Num a => a -> a
abs Float
a forall a. Ord a => a -> a -> Bool
<= Float
1e-6
instance Epsilon Double where
nearZero :: Double -> Bool
nearZero Double
a = forall a. Num a => a -> a
abs Double
a forall a. Ord a => a -> a -> Bool
<= Double
1e-12
instance Epsilon CFloat where
nearZero :: CFloat -> Bool
nearZero CFloat
a = forall a. Num a => a -> a
abs CFloat
a forall a. Ord a => a -> a -> Bool
<= CFloat
1e-6
instance Epsilon CDouble where
nearZero :: CDouble -> Bool
nearZero CDouble
a = forall a. Num a => a -> a
abs CDouble
a forall a. Ord a => a -> a -> Bool
<= CDouble
1e-12
instance (Epsilon a, RealFloat a) => Epsilon (Complex a) where
nearZero :: Complex a -> Bool
nearZero = forall a. Epsilon a => a -> Bool
nearZero forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. RealFloat a => Complex a -> a
magnitude