X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FComparisons.hs;h=58a57473fac441f5c7ff305a565c5e6b0bc26cee;hb=35bc3798d28ed65ab970cf158082bf8d68e2c480;hp=4a8144469415668327567717239844a4b1c85a22;hpb=d1ee387490ef0ada8781f4bf81f82cce7f0006ba;p=spline3.git diff --git a/src/Comparisons.hs b/src/Comparisons.hs index 4a81444..58a5747 100644 --- a/src/Comparisons.hs +++ b/src/Comparisons.hs @@ -1,5 +1,14 @@ -- | Functions for comparing 'Double' values. -module Comparisons +module Comparisons ( + (~=), + (~~=), + almost_equals, + kinda_equals, + nearly_equals, + nearly_ge, + non_very_positive_entries, + very_positive, + ) where -- | epsilon is the value that will be used in all tests that require @@ -10,19 +19,34 @@ epsilon = 0.0001 -- | A tiny margin of error. theta :: Double -theta = 0.00000000000001 +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 @@ -32,11 +56,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 @@ -44,8 +71,12 @@ 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