metabrush/src/lib/Math/Epsilon.hs

16 lines
407 B
Haskell
Raw Normal View History

2020-08-19 03:28:47 +00:00
{-# LANGUAGE ScopedTypeVariables #-}
module Math.Epsilon
( epsilon, nearZero )
2020-08-19 03:28:47 +00:00
where
--------------------------------------------------------------------------------
{-# SPECIALISE epsilon :: Float #-}
{-# SPECIALISE epsilon :: Double #-}
epsilon :: forall r. RealFloat r => r
epsilon = encodeFloat 1 ( 5 - floatDigits ( 0 :: r ) )
nearZero :: RealFloat r => r -> Bool
nearZero x = abs x < epsilon