packages feed

ieee 0.4 → 0.5

raw patch · 3 files changed

+151/−25 lines, 3 filesdep ~base

Dependency ranges changed: base

Files

Data/AEq.hs view
@@ -12,6 +12,7 @@     AEq(..),     ) where +import Foreign.C.Types import Data.Int import Data.Word import Data.Complex@@ -33,32 +34,48 @@     -- approximately equal, the polar forms are compared, instead.     (~==) :: a -> a -> Bool     +identicalRealFloat :: (RealFloat a) => a -> a -> Bool+identicalRealFloat x y = +    (x == y) || (isNaN x && isNaN y) -instance AEq Float where-    (===) x y =-        (x == y) || (isNaN x && isNaN y)-    (~==) x y =   -        (x == y) || (abs (x - y) < epsilon) || (eqRel delta x y) || (isNaN x && isNaN y)+approxEqRealFloat :: (RealFloat a) => a -> a -> Bool+approxEqRealFloat x y =+    (x == y) || (abs (x - y) < epsilon) || (eqRel delta x y) || (isNaN x && isNaN y) +identicalComplexFloat :: (RealFloat a) => Complex a -> Complex a -> Bool+identicalComplexFloat (x1 :+ y1) (x2 :+ y2) =+    (identicalRealFloat x1 x2) && (identicalRealFloat y1 y2)++approxEqComplexFloat :: (RealFloat a) => Complex a -> Complex a -> Bool+approxEqComplexFloat z1@(x1 :+ y1) z2@(x2 :+ y2) = let+    (r1,c1) = polar z1+    (r2,c2) = polar z2+    c  = min c1 c2+    c' = max c1 c2 in+    ((approxEqRealFloat x1 x2 && approxEqRealFloat y1 y2) +     || ((approxEqRealFloat r1 r2) +         && ((approxEqRealFloat c1 c2) || (approxEqRealFloat (c + 2 * pi) c'))))++instance AEq Float where+    (===) = identicalRealFloat+    (~==) = approxEqRealFloat+         instance AEq Double where-    (===) x y =-        (x == y) || (isNaN x && isNaN y)-    (~==) x y = -        (x == y) || (abs (x - y) < epsilon) || (eqRel delta x y) || (isNaN x && isNaN y)+    (===) = identicalRealFloat+    (~==) = approxEqRealFloat -instance (RealFloat a, AEq a) => AEq (Complex a) where-    (===) (x1 :+ y1) (x2 :+ y2) = ((===) x1 x2) && ((===) y1 y2)-    (~==) z1@(x1 :+ y1) z2@(x2 :+ y2) = -        let (r1,c1) = polar z1-            (r2,c2) = polar z2-            c  = min c1 c2-            c' = max c1 c2-        in (x1 ~== x2 && y1 ~== y2) || (r1 ~== r2) && ((c1 ~== c2) || (c + 2 * pi ~== c'))+instance (RealFloat a) => AEq (Complex a) where+    (===) = identicalComplexFloat+    (~==) = approxEqComplexFloat  instance AEq Bool where     (===) = (==)     (~==) = (==)-    ++instance AEq Char where+    (===) = (==)+    (~==) = (==)+         instance AEq Int where     (===) = (==)     (~==) = (==)@@ -79,6 +96,14 @@     (===) = (==)     (~==) = (==) +instance AEq Integer where+    (===) = (==)+    (~==) = (==)++instance AEq Ordering where+    (===) = (==)+    (~==) = (==)+ instance AEq Word where     (===) = (==)     (~==) = (==)@@ -103,6 +128,102 @@     (===) = (==)     (~==) = (==)     +instance AEq CChar where+    (===) = (==)+    (~==) = (==)++instance AEq CSChar where+    (===) = (==)+    (~==) = (==)++instance AEq CUChar where+    (===) = (==)+    (~==) = (==)++instance AEq CShort where+    (===) = (==)+    (~==) = (==)++instance AEq CUShort where+    (===) = (==)+    (~==) = (==)++instance AEq CInt where+    (===) = (==)+    (~==) = (==)++instance AEq CUInt where+    (===) = (==)+    (~==) = (==)++instance AEq CLong where+    (===) = (==)+    (~==) = (==)++instance AEq CULong where+    (===) = (==)+    (~==) = (==)++instance AEq CPtrdiff where+    (===) = (==)+    (~==) = (==)++instance AEq CSize where+    (===) = (==)+    (~==) = (==)++instance AEq CWchar where+    (===) = (==)+    (~==) = (==)++instance AEq CSigAtomic where+    (===) = (==)+    (~==) = (==)++instance AEq CLLong where+    (===) = (==)+    (~==) = (==)++instance AEq CULLong where+    (===) = (==)+    (~==) = (==)++instance AEq CIntPtr where+    (===) = (==)+    (~==) = (==)++instance AEq CUIntPtr where+    (===) = (==)+    (~==) = (==)++instance AEq CIntMax where+    (===) = (==)+    (~==) = (==)++instance AEq CUIntMax where+    (===) = (==)+    (~==) = (==)++instance AEq CClock where+    (===) = (==)+    (~==) = (==)++instance AEq CTime where+    (===) = (==)+    (~==) = (==)++instance AEq CFloat where+    (===) = identicalRealFloat+    (~==) = approxEqRealFloat+        +instance AEq CDouble where+    (===) = identicalRealFloat+    (~==) = approxEqRealFloat++instance AEq CLDouble where+    (===) = identicalRealFloat+    (~==) = approxEqRealFloat+ instance (AEq a, AEq b) => AEq (a,b) where     (===) (a1,b1) (a2,b2) = ((===) a1 a2) && ((===) b1 b2)     (~==) (a1,b1) (a2,b2) = ((~==) a1 a2) && ((~==) b1 b2)@@ -114,6 +235,11 @@ instance (AEq a, AEq b, AEq c, AEq d) => AEq (a,b,c,d) where     (===) (a1,b1,c1,d1) (a2,b2,c2,d2) = ((===) a1 a2) && ((===) b1 b2) && ((===) c1 c2) && ((===) d1 d2)     (~==) (a1,b1,c1,d1) (a2,b2,c2,d2) = ((~==) a1 a2) && ((~==) b1 b2) && ((~==) c1 c2) && ((~==) d1 d2)++instance (AEq a, AEq b, AEq c, AEq d, AEq e) => AEq (a,b,c,d,e) where+    (===) (a1,b1,c1,d1,e1) (a2,b2,c2,d2,e2) = ((===) a1 a2) && ((===) b1 b2) && ((===) c1 c2) && ((===) d1 d2) && ((===) e1 e2)+    (~==) (a1,b1,c1,d1,e1) (a2,b2,c2,d2,e2) = ((~==) a1 a2) && ((~==) b1 b2) && ((~==) c1 c2) && ((~==) d1 d2) && ((~==) e1 e2)+  compareListsWith :: (a -> a -> Bool) -> [a] -> [a] -> Bool compareListsWith _ [] [] = True
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) Patrick Perry <patperry@stanford.edu> 2008+Copyright (c) Patrick Perry <patperry@gmail.com> 2009  All rights reserved. 
ieee.cabal view
@@ -1,6 +1,6 @@ name:            ieee-version:         0.4-homepage:        http://stat.stanford.edu/~patperry/code/ieee+version:         0.5+homepage:        http://github.com/patperry/ieee synopsis:        Approximate comparisons for IEEE floating point numbers description:     Approximate comparison of floating point numbers based on the@@ -11,12 +11,12 @@ category:        Math license:         BSD3 license-file:    LICENSE-copyright:       (c) 2008. Patrick Perry <patperry@stanford.edu>+copyright:       (c) 2009. Patrick Perry <patperry@gmail.com> author:          Patrick Perry-maintainer:      Patrick Perry <patperry@stanford.edu>+maintainer:      Patrick Perry <patperry@gmail.com> cabal-version: >= 1.2.0 build-type:      Custom-tested-with:     GHC ==6.8.2+tested-with:     GHC ==6.10.1  extra-source-files: tests/Properties.hs @@ -24,6 +24,6 @@     exposed-modules: Data.AEq                      Numeric.IEEE -    build-depends: base+    build-depends:   base >= 3 && < 5      ghc-options:     -Wall