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
25 -- | x almost equals y if x is within 'theta' of y.
27 -- Only used in tests.
29 nearly_equals :: Double -> Double -> Bool
34 -- | Nearly greater-than or equal-to.
36 -- Only used in tests.
38 nearly_ge :: Double -> Double -> Bool
40 (x > y) || (x `nearly_equals` y)
43 -- | x almost equals y if x is within 'epsilon' of y.
45 -- Only used in tests.
47 almost_equals :: Double -> Double -> Bool
49 (abs (x - y)) < epsilon
52 (~=) :: Double -> Double -> Bool
56 -- | Like 'almost_equals', except much more tolerant. The difference
57 -- between the two arguments must be less than one percent of the sum
58 -- of their magnitudes.
60 -- Only used in tests.
62 kinda_equals :: Double -> Double -> Bool
64 (abs (x - y)) < threshold
66 threshold = ((abs x) + (abs y)) / 100.0
69 (~~=) :: Double -> Double -> Bool
73 -- | x is very positive if it is 'epsilon' greater than zero.
75 -- Only used in tests.
77 very_positive :: Double -> Bool
82 -- | Takes a list of 'Double' and returns the ones which are not very
84 non_very_positive_entries :: [Double] -> [Double]
85 non_very_positive_entries = filter (not . very_positive)