From: Michael Orlitzky Date: Sun, 28 Aug 2011 01:13:03 +0000 (-0400) Subject: Add the theta tolerance and nearly_equals, nearly_ge comparisons. X-Git-Tag: 0.0.1~211 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=d1ee387490ef0ada8781f4bf81f82cce7f0006ba;p=spline3.git Add the theta tolerance and nearly_equals, nearly_ge comparisons. --- diff --git a/src/Comparisons.hs b/src/Comparisons.hs index 6d8dc70..4a81444 100644 --- a/src/Comparisons.hs +++ b/src/Comparisons.hs @@ -8,6 +8,17 @@ where epsilon :: Double epsilon = 0.0001 +-- | A tiny margin of error. +theta :: Double +theta = 0.00000000000001 + +-- | x almost equals y if x is within 'theta' of y. +nearly_equals :: Double -> Double -> Bool +nearly_equals x y = (abs (x - y)) < theta + +-- | Nearly greater-than or equal-to. +nearly_ge :: Double -> Double -> Bool +x `nearly_ge` y = (x > y) || (x `nearly_equals` y) -- | x almost equals y if x is within 'epsilon' of y. almost_equals :: Double -> Double -> Bool