metabrush/src/lib/Math/Epsilon.hs
sheaf 58ca70c1bd optimise root-finding functions
* use PrimArray to represent polynomials
  * add some strictness annotations
  * turn on some optimisation flags
  * use quadratic formula for quadratic polynomials
2020-09-19 00:43:07 +02:00

16 lines
407 B
Haskell

{-# LANGUAGE ScopedTypeVariables #-}
module Math.Epsilon
( epsilon, nearZero )
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