From 8c8a0f9d8df50b2fe29562790360dd615cf3e56a Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 10 Jun 2011 14:56:28 -0400 Subject: [PATCH] Add the kinda_equals comparison. --- src/Comparisons.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 -- 2.43.2