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

Safe HaskellSafe
LanguageHaskell2010

Data.Connection.Float

Contents

Synopsis

Connections

f32i08 :: Conn k Float (Extended Int8) Source #

All Int08 values are exactly representable in a Float.

f32i16 :: Conn k Float (Extended Int16) Source #

All Int16 values are exactly representable in a Float.

min32 :: Float -> Float -> Float Source #

A NaN-handling min32 function.

min32 x NaN = x
min32 NaN y = y

max32 :: Float -> Float -> Float Source #

A NaN-handling max32 function.

max32 x NaN = x
max32 NaN y = y

covers :: Float -> Float -> Bool Source #

Covering relation on the N5 lattice of floats.

https://en.wikipedia.org/wiki/Covering_relation

>>> covers 1 (shift 1 1)
True
>>> covers 1 (shift 2 1)
False

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

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

>>> ulp 1.0 (shift 1 1.0)
Just (LT,1)
>>> ulp (0.0/0.0) 1.0
Nothing

shift :: Int32 -> Float -> Float Source #

Shift a float by n units of least precision.

>>> shift 1 0
1.0e-45
>>> shift 1 $ 0/0
NaN
>>> shift (-1) $ 0/0
NaN
>>> shift 1 $ 1/0
Infinity

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

Compare two 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/.

epsilon :: Float Source #

Difference between 1 and the smallest representable value greater than 1.

epsilon = shift 1 1 - 1
>>> epsilon
1.1920929e-7