X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FComparisons.hs;h=5f4c7149091edc8ca4c83cd0a6b9caf3e4df2430;hb=83ef0aaeae074756e4ee90d72d3e27e74e136061;hp=3bf4e246bcfba473634b255fb1befb8187a84b8f;hpb=3f7331f579118687cd73b977ce6aa7d401f88a09;p=spline3.git diff --git a/src/Comparisons.hs b/src/Comparisons.hs index 3bf4e24..5f4c714 100644 --- a/src/Comparisons.hs +++ b/src/Comparisons.hs @@ -7,31 +7,49 @@ module Comparisons ( nearly_equals, nearly_ge, non_very_positive_entries, - very_positive, - ) + very_positive ) 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. + -- epsilon :: Double epsilon = 0.0001 + -- | A tiny margin of error. +-- theta :: Double theta = 0.0000000000001 + -- | x almost equals y if x is within 'theta' of y. +-- +-- Only used in tests. +-- nearly_equals :: Double -> Double -> Bool -nearly_equals x y = (abs (x - y)) < theta +nearly_equals x y = + (abs (x - y)) < theta + -- | Nearly greater-than or equal-to. +-- +-- Only used in tests. +-- nearly_ge :: Double -> Double -> Bool -x `nearly_ge` y = (x > y) || (x `nearly_equals` y) +x `nearly_ge` y = + (x > y) || (x `nearly_equals` y) + -- | x almost equals y if x is within 'epsilon' of y. +-- +-- Only used in tests. +-- almost_equals :: Double -> Double -> Bool -almost_equals x y = (abs (x - y)) < epsilon +almost_equals x y = + (abs (x - y)) < epsilon infix 4 ~= (~=) :: Double -> Double -> Bool @@ -41,11 +59,14 @@ infix 4 ~= -- | 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. +-- +-- Only used in tests. +-- kinda_equals :: Double -> Double -> Bool kinda_equals x y = - (abs (x - y)) < threshold - where - threshold = ((abs x) + (abs y)) / 100.0 + (abs (x - y)) < threshold + where + threshold = ((abs x) + (abs y)) / 100.0 infix 4 ~~= (~~=) :: Double -> Double -> Bool @@ -53,11 +74,16 @@ infix 4 ~~= -- | x is very positive if it is 'epsilon' greater than zero. +-- +-- Only used in tests. +-- very_positive :: Double -> Bool -very_positive x = x - epsilon > 0 +very_positive x = + x - epsilon > 0 -- | Takes a list of 'Double' and returns the ones which are not very -- positive. +-- non_very_positive_entries :: [Double] -> [Double] non_very_positive_entries = filter (not . very_positive)