1{-# LANGUAGE NoImplicitPrelude #-}
2
3module Functions
4    (
5      approxEq
6    , approxEqWith
7    ) where
8
9import Prelude.Compat
10
11approxEq :: (Fractional a, Ord a) => a -> a -> Bool
12approxEq = approxEqWith 1e-15 1e-15
13
14approxEqWith :: (Fractional a, Ord a) => a -> a -> a -> a -> Bool
15approxEqWith maxAbsoluteError maxRelativeError a b =
16    a == b || d < maxAbsoluteError ||
17    d / max (abs b) (abs a) <= maxRelativeError
18  where d = abs (a - b)
19