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