From: Michael Orlitzky Date: Fri, 10 Jun 2011 18:56:28 +0000 (-0400) Subject: Add the kinda_equals comparison. X-Git-Tag: 0.0.1~281 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=8c8a0f9d8df50b2fe29562790360dd615cf3e56a;p=spline3.git Add the kinda_equals comparison. --- diff --git a/src/Comparisons.hs b/src/Comparisons.hs index b5d76d5..6d8dc70 100644 --- a/src/Comparisons.hs +++ b/src/Comparisons.hs @@ -18,6 +18,20 @@ infix 4 ~= (~=) = almost_equals +-- | Like 'almost_equals', except much more tolerant. The difference +-- between the two arguments must be less than one percent of the sum +-- of their magnitudes. +kinda_equals :: Double -> Double -> Bool +kinda_equals x y = + (abs (x - y)) < threshold + where + threshold = ((abs x) + (abs y)) / 100.0 + +infix 4 ~~= +(~~=) :: Double -> Double -> Bool +(~~=) = kinda_equals + + -- | x is very positive if it is 'epsilon' greater than zero. very_positive :: Double -> Bool very_positive x = x - epsilon > 0