fp-ieee-0.1.0.6: IEEE 754-2019 compliant operations

Safe Haskell | None
Language | Haskell2010

Numeric.Floating.IEEE.NaN

Description

This module provides the typeclass for NaN manipulation: `RealFloatNaN`.

In addition to `Float` and `Double`, a couple of floating-point types provided by third-party libraries can be supported via package flags: `Half` via `half` and `Float128` via `float128`.

Synopsis

- class RealFloat a => RealFloatNaN a where
  - copySign :: a -> a -> a
  - isSignMinus :: a -> Bool
  - isSignaling :: a -> Bool
  - getPayload :: a -> a
  - setPayload :: a -> a
  - setPayloadSignaling :: a -> a
  - classify :: a -> Class
  - equalByTotalOrder :: a -> a -> Bool
  - compareByTotalOrder :: a -> a -> Ordering
- data Class
  - = SignalingNaN
  - | QuietNaN
  - | NegativeInfinity
  - | NegativeNormal
  - | NegativeSubnormal
  - | NegativeZero
  - | PositiveZero
  - | PositiveSubnormal
  - | PositiveNormal
  - | PositiveInfinity
- newtype TotallyOrdered a = TotallyOrdered a

# Documentation

class RealFloat a => RealFloatNaN a where Source #

An instance of this class supports manipulation of NaN.

Minimal complete definition

(copySign | isSignMinus), (isSignaling | classify), getPayload, setPayload, setPayloadSignaling

Methods

copySign :: a -> a -> a Source #

Returns the first operand, with the sign of the second.

IEEE 754 `copySign` operation.

isSignMinus :: a -> Bool Source #

Returns `True` if the operand is a negative number, negative infinity, negative zero, or a NaN with negative sign bit.

IEEE 754 `isSignMinus` operation.

isSignaling :: a -> Bool Source #

Returns `True` if the operand is a signaling NaN.

IEEE 754 `isSignaling` operation.

Warning: GHC's optimizer is not aware of signaling NaNs.

getPayload :: a -> a Source #

Returns the payload of a NaN. Returns `-1` if the operand is not a NaN.

IEEE 754 `getPayload` operation.

setPayload :: a -> a Source #

Returns a quiet NaN with a given payload. Returns a positive zero if the payload is invalid.

IEEE 754 `setPayload` operation.

setPayloadSignaling :: a -> a Source #

Returns a signaling NaN with a given payload. Returns a positive zero if the payload is invalid.

IEEE 754 `setPayloadSignaling` operation.

classify :: a -> Class Source #

IEEE 754 `class` operation.

equalByTotalOrder :: a -> a -> Bool Source #

Equality with IEEE 754 `totalOrder` operation.

compareByTotalOrder :: a -> a -> Ordering Source #

Comparison with IEEE 754 `totalOrder` operation.

Floating-point numbers should be ordered as, \(-\mathrm{qNaN} < -\mathrm{sNaN} < -\infty < \text{negative reals} < -0 < +0 < \text{positive reals} < +\infty < +\mathrm{sNaN} < +\mathrm{qNaN}\).

#### Instances

Instances details

RealFloatNaN Double Source # |

Instance details

Defined in Numeric.Floating.IEEE.Internal.NaN

Methods

copySign :: Double -> Double -> Double Source #

isSignMinus :: Double -> Bool Source #

isSignaling :: Double -> Bool Source #

getPayload :: Double -> Double Source #

setPayload :: Double -> Double Source #

setPayloadSignaling :: Double -> Double Source #

classify :: Double -> Class Source #

equalByTotalOrder :: Double -> Double -> Bool Source #

compareByTotalOrder :: Double -> Double -> Ordering Source #

RealFloatNaN Float Source # |

Instance details

Defined in Numeric.Floating.IEEE.Internal.NaN

Methods

copySign :: Float -> Float -> Float Source #

isSignMinus :: Float -> Bool Source #

isSignaling :: Float -> Bool Source #

getPayload :: Float -> Float Source #

setPayload :: Float -> Float Source #

setPayloadSignaling :: Float -> Float Source #

classify :: Float -> Class Source #

equalByTotalOrder :: Float -> Float -> Bool Source #

compareByTotalOrder :: Float -> Float -> Ordering Source #

data Class Source #

The classification of floating-point values.

Constructors

SignalingNaN |
QuietNaN |
NegativeInfinity |
NegativeNormal |
NegativeSubnormal |
NegativeZero |
PositiveZero |
PositiveSubnormal |
PositiveNormal |
PositiveInfinity |

#### Instances

Instances details

Enum Class Source # |

Instance details

Defined in Numeric.Floating.IEEE.Internal.Classify

Methods

succ :: Class -> Class Source #

pred :: Class -> Class Source #

toEnum :: Int -> Class Source #

fromEnum :: Class -> Int Source #

enumFrom :: Class -> [Class] Source #

enumFromThen :: Class -> Class -> [Class] Source #

enumFromTo :: Class -> Class -> [Class] Source #

enumFromThenTo :: Class -> Class -> Class -> [Class] Source #

Read Class Source # |
Instance details Defined in Numeric.Floating.IEEE.Internal.Classify Methods readsPrec :: Int -> ReadS Class Source # readList :: ReadS [Class] Source # readPrec :: ReadPrec Class Source # readListPrec :: ReadPrec [Class] Source #
Show Class Source # |
Instance details Defined in Numeric.Floating.IEEE.Internal.Classify Methods showsPrec :: Int -> Class -> ShowS Source # show :: Class -> String Source # showList :: [Class] -> ShowS Source #
Eq Class Source # |
Instance details Defined in Numeric.Floating.IEEE.Internal.Classify Methods (==) :: Class -> Class -> Bool Source # (/=) :: Class -> Class -> Bool Source #
Ord Class Source # |
Instance details Defined in Numeric.Floating.IEEE.Internal.Classify Methods compare :: Class -> Class -> Ordering Source # (<) :: Class -> Class -> Bool Source # (<=) :: Class -> Class -> Bool Source # (>) :: Class -> Class -> Bool Source # (>=) :: Class -> Class -> Bool Source # max :: Class -> Class -> Class Source # min :: Class -> Class -> Class Source #

newtype TotallyOrdered a Source #

A newtype wrapper to compare floating-point numbers by `totalOrder` predicate.

Constructors

TotallyOrdered a |

#### Instances

Instances details

Show a => Show (TotallyOrdered a) Source # |
Instance details Defined in Numeric.Floating.IEEE.Internal.NaN Methods showsPrec :: Int -> TotallyOrdered a -> ShowS Source # show :: TotallyOrdered a -> String Source # showList :: [TotallyOrdered a] -> ShowS Source #
RealFloatNaN a => Eq (TotallyOrdered a) Source # |
Instance details Defined in Numeric.Floating.IEEE.Internal.NaN Methods (==) :: TotallyOrdered a -> TotallyOrdered a -> Bool Source # (/=) :: TotallyOrdered a -> TotallyOrdered a -> Bool Source #
RealFloatNaN a => Ord (TotallyOrdered a) Source # |

Instance details

Defined in Numeric.Floating.IEEE.Internal.NaN

Methods

compare :: TotallyOrdered a -> TotallyOrdered a -> Ordering Source #

(<) :: TotallyOrdered a -> TotallyOrdered a -> Bool Source #

(<=) :: TotallyOrdered a -> TotallyOrdered a -> Bool Source #

(>) :: TotallyOrdered a -> TotallyOrdered a -> Bool Source #

(>=) :: TotallyOrdered a -> TotallyOrdered a -> Bool Source #

max :: TotallyOrdered a -> TotallyOrdered a -> TotallyOrdered a Source #

min :: TotallyOrdered a -> TotallyOrdered a -> TotallyOrdered a Source #