X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FComparisons.hs;h=6d8dc70d846e08159c9c4ae6ea49b11a530a25a2;hb=46b1f2e3741d6571c2f931371222f8970b6c7f63;hp=4bf4cebb69ece2947eb1deccf0dfa9cfda20f266;hpb=58cf11569acb270995d2de924dda03ef526647e2;p=spline3.git diff --git a/src/Comparisons.hs b/src/Comparisons.hs index 4bf4ceb..6d8dc70 100644 --- a/src/Comparisons.hs +++ b/src/Comparisons.hs @@ -3,8 +3,8 @@ module Comparisons where -- | epsilon is the value that will be used in all tests that require --- some measure of "closeness." Increasing it will make those tests --- more tolerant. +-- some measure of \"closeness.\" Increasing it will make those +-- tests more tolerant. epsilon :: Double epsilon = 0.0001 @@ -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