connections-0.3.2: Orders, Galois connections, and lattices.

Safe HaskellSafe
LanguageHaskell2010

Data.Connection.Float

Contents

Synopsis

Float

ulp32 :: Float -> Float -> Maybe (Ordering, Word32) Source #

Compute the signed distance between two floats in units of least precision.

>>> ulp32 1.0 (shift32 1 1.0)
Just (LT,1)
>>> ulp32 (0.0/0.0) 1.0
Nothing

near32 :: Word32 -> Float -> Float -> Bool Source #

Compare two floats for approximate equality.

Required accuracy is specified in units of least precision.

See https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/.

shift32 :: Int32 -> Float -> Float Source #

Shift a float by n units of least precision.

>>> shift32 1 0
1.0e-45
>>> shift32 1 1 - 1
1.1920929e-7
>>> shift32 1 $ 0/0
Infinity
>>> shift32 (-1) $ 0/0
-Infinity
>>> shift32 1 $ 1/0
Infinity

Double

ulp64 :: Double -> Double -> Maybe (Ordering, Word64) Source #

Compute the signed distance between two doubles in units of least precision.

>>> ulp64 1.0 (shift64 1 1.0)
Just (LT,1)
>>> ulp64 (0.0/0.0) 1.0
Nothing

near64 :: Word64 -> Double -> Double -> Bool Source #

Compare two double-precision floats for approximate equality.

Required accuracy is specified in units of least precision.

See also https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/.

shift64 :: Int64 -> Double -> Double Source #

Shift by n units of least precision.

>>> shift64 1 0
5.0e-324
>>> shift64 1 1 - 1
2.220446049250313e-16
>>> shift64 1 $ 0/0
Infinity
>>> shift64 (-1) $ 0/0
-Infinity
>>> shift64 1 $ 1/0
Infinity