X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FComparisons.hs;h=6d8dc70d846e08159c9c4ae6ea49b11a530a25a2;hb=46b1f2e3741d6571c2f931371222f8970b6c7f63;hp=b5d76d5b11d6da85ca386021be918041d83abd53;hpb=d60de7d5ab06d6c3261826b843ee89cf12ab9667;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