Add approximate floating point comparison
This commit is contained in:
parent
8e58fc8a1a
commit
be119f5116
|
@ -28,10 +28,22 @@ interface (Eq a, Neg a, Fractional a) => FieldCmp a where
|
||||||
|
|
||||||
|
|
||||||
export
|
export
|
||||||
(Ord a, Abs a, Neg a, Fractional a) => FieldCmp a where
|
FieldCmp Double where
|
||||||
abslt x y = abs x < abs y
|
abslt = (<) `on` abs
|
||||||
|
|
||||||
|
|
||||||
|
-- Alternative implementations of `Eq` and `FieldCmp` that compare floating
|
||||||
|
-- point numbers approximately, useful when working with transforms
|
||||||
|
namespace Eq
|
||||||
|
export
|
||||||
|
WithEpsilon : Double -> Eq Double
|
||||||
|
WithEpsilon ep = MkEq (\x,y => x - y < ep) (\x,y => x - y >= ep)
|
||||||
|
|
||||||
|
namespace FieldCmp
|
||||||
|
export
|
||||||
|
WithEpsilon : Double -> FieldCmp Double
|
||||||
|
WithEpsilon ep = MkFieldCmp @{WithEpsilon ep} ((<) `on` abs)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Multiplication
|
-- Multiplication
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
@ -82,8 +94,8 @@ interface MultMonoid a => MultGroup a where
|
||||||
constructor MkMultGroup
|
constructor MkMultGroup
|
||||||
||| Calculate the inverse of the matrix or transformation.
|
||| Calculate the inverse of the matrix or transformation.
|
||||||
||| WARNING: This function will not check if an inverse exists for the given
|
||| WARNING: This function will not check if an inverse exists for the given
|
||||||
||| input, and will happily return results containing NaN values. To avoid
|
||| input, and will happily divide by zero or return results containing NaN.
|
||||||
||| this, use `tryInverse` instead.
|
||| To avoid this, use `tryInverse` instead.
|
||||||
inverse : a -> a
|
inverse : a -> a
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue