]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Comparisons.hs
Add two new comparisons, very_positive and non_very_positive_entries.
[spline3.git] / src / Comparisons.hs
1 module Comparisons
2 where
3
4 -- | epsilon is the value that will be used in all tests that require
5 -- some measure of "closeness." Increasing it will make those tests
6 -- more tolerant.
7 epsilon :: Double
8 epsilon = 0.0001
9
10
11 -- | x almost equals y if x is within 'epsilon' of y.
12 almost_equals :: Double -> Double -> Bool
13 almost_equals x y = (abs (x - y)) < epsilon
14
15 infix 4 ~=
16 (~=) :: Double -> Double -> Bool
17 (~=) = almost_equals
18
19
20 -- | x is very positive if it is 'epsilon' greater than zero.
21 very_positive :: Double -> Bool
22 very_positive x = x - epsilon > 0
23
24
25 -- | Takes a list of Doubles and returns the ones which are not very
26 -- positive.
27 non_very_positive_entries :: [Double] -> [Double]
28 non_very_positive_entries = filter (not . very_positive)