X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FComparisons.hs;fp=src%2FComparisons.hs;h=6d8dc70d846e08159c9c4ae6ea49b11a530a25a2;hb=8c8a0f9d8df50b2fe29562790360dd615cf3e56a;hp=b5d76d5b11d6da85ca386021be918041d83abd53;hpb=374d036a09ca086d73dabd7196d888ff76b90610;p=spline3.git 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