From: Michael Orlitzky Date: Sat, 7 May 2011 00:31:37 +0000 (-0400) Subject: Add two new comparisons, very_positive and non_very_positive_entries. X-Git-Tag: 0.0.1~330 X-Git-Url: http://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=28710758dac0a1241911c6ba296b0685b877b5e3;hp=1b5119ed681268c16c08ee7c9cc7b1766d363a6e;p=spline3.git Add two new comparisons, very_positive and non_very_positive_entries. --- diff --git a/src/Comparisons.hs b/src/Comparisons.hs index f4462a0..506ebab 100644 --- a/src/Comparisons.hs +++ b/src/Comparisons.hs @@ -1,10 +1,28 @@ 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. +epsilon :: Double +epsilon = 0.0001 + +-- | x almost equals y if x is within 'epsilon' of y. almost_equals :: Double -> Double -> Bool -almost_equals x y = (abs (x - y)) < 0.0001 +almost_equals x y = (abs (x - y)) < epsilon infix 4 ~= (~=) :: Double -> Double -> Bool (~=) = almost_equals + + +-- | x is very positive if it is 'epsilon' greater than zero. +very_positive :: Double -> Bool +very_positive x = x - epsilon > 0 + + +-- | Takes a list of Doubles and returns the ones which are not very +-- positive. +non_very_positive_entries :: [Double] -> [Double] +non_very_positive_entries = filter (not . very_positive)