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.
22 -- | A tiny margin of error.
25 theta = 0.0000000000001
28 -- | x almost equals y if x is within 'theta' of y.
30 -- Only used in tests.
32 nearly_equals :: Double -> Double -> Bool
37 -- | Nearly greater-than or equal-to.
39 -- Only used in tests.
41 nearly_ge :: Double -> Double -> Bool
43 (x > y) || (x `nearly_equals` y)
46 -- | x almost equals y if x is within 'epsilon' of y.
48 -- Only used in tests.
50 almost_equals :: Double -> Double -> Bool
52 (abs (x - y)) < epsilon
55 (~=) :: Double -> Double -> Bool
59 -- | Like 'almost_equals', except much more tolerant. The difference
60 -- between the two arguments must be less than one percent of the sum
61 -- of their magnitudes.
63 -- Only used in tests.
65 kinda_equals :: Double -> Double -> Bool
67 (abs (x - y)) < threshold
69 threshold = ((abs x) + (abs y)) / 100.0
72 (~~=) :: Double -> Double -> Bool
76 -- | x is very positive if it is 'epsilon' greater than zero.
78 -- Only used in tests.
80 very_positive :: Double -> Bool
85 -- | Takes a list of 'Double' and returns the ones which are not very
88 non_very_positive_entries :: [Double] -> [Double]
89 non_very_positive_entries = filter (not . very_positive)