Commit 3bcddcd7 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

Use exact comparision for doubles

Comparision with (a-b < ɛ) is not transitive and thus doesn't induce
an equality relation. Since the whole job of the algorithm is to
partition according to an equality relation, this may be problematic.

Instead, to compare doubles a and b, we now round both values to
floats and compare those exactly. This means that we get a proper
equality relation, even if it fails to distinguish some states and
wrongly distinguishes others when compared to operations on true real
numbers.
parent 55768977
......@@ -6,8 +6,8 @@
module Data.Float.Utils (EqDouble, fromDouble, MaxDouble(..)) where
import Control.DeepSeq ( NFData )
import Data.AEq
import qualified Numeric.IEEE as IEEE
import GHC.Float ( double2Float )
-- | A wrapper around double that provides an approximate 'Eq' instance.
......@@ -31,8 +31,11 @@ fromDouble = EqDouble
{-# INLINE fromDouble #-}
-- | We cast the double to float and compare the result exactly. This ensures a
-- transitive relation.
instance Eq EqDouble where
(EqDouble a) == (EqDouble b) = a ~== b
(EqDouble a) == (EqDouble b) =
(double2Float a) == (double2Float b)
newtype MaxDouble = MaxDouble Double
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment