1 -- | Functions for comparing 'Double' values.
9 non_very_positive_entries,
14 -- | epsilon is the value that will be used in all tests that require
15 -- some measure of \"closeness.\" Increasing it will make those
16 -- tests more tolerant.
20 -- | A tiny margin of error.
22 theta = 0.0000000000001
24 -- | x almost equals y if x is within 'theta' of y.
25 nearly_equals :: Double -> Double -> Bool
26 nearly_equals x y = (abs (x - y)) < theta
28 -- | Nearly greater-than or equal-to.
29 nearly_ge :: Double -> Double -> Bool
30 x `nearly_ge` y = (x > y) || (x `nearly_equals` y)
32 -- | x almost equals y if x is within 'epsilon' of y.
33 almost_equals :: Double -> Double -> Bool
34 almost_equals x y = (abs (x - y)) < epsilon
37 (~=) :: Double -> Double -> Bool
41 -- | Like 'almost_equals', except much more tolerant. The difference
42 -- between the two arguments must be less than one percent of the sum
43 -- of their magnitudes.
44 kinda_equals :: Double -> Double -> Bool
46 (abs (x - y)) < threshold
48 threshold = ((abs x) + (abs y)) / 100.0
51 (~~=) :: Double -> Double -> Bool
55 -- | x is very positive if it is 'epsilon' greater than zero.
56 very_positive :: Double -> Bool
57 very_positive x = x - epsilon > 0
60 -- | Takes a list of 'Double' and returns the ones which are not very
62 non_very_positive_entries :: [Double] -> [Double]
63 non_very_positive_entries = filter (not . very_positive)