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