ieee754-0.7.3: Utilities for dealing with IEEE floating point numbers

Stability | experimental
Maintainer | Patrick Perry <patperry@gmail.com>
Safe Haskell | None

Numeric.IEEE

Contents

- IEEE type class
- NaN-aware minimum and maximum

Description

Operations on IEEE floating point numbers.

Synopsis

- class RealFloat a => IEEE a where
  - infinity :: a
  - minNormal :: a
  - maxFinite :: a
  - epsilon :: a
  - copySign :: a -> a -> a
  - identicalIEEE :: a -> a -> Bool
  - succIEEE :: a -> a
  - predIEEE :: a -> a
  - bisectIEEE :: a -> a -> a
  - sameSignificandBits :: a -> a -> Int
  - nan :: a
  - nanWithPayload :: Word64 -> a
  - maxNaNPayload :: a -> Word64
  - nanPayload :: a -> Word64
- minNum :: RealFloat a => a -> a -> a
- maxNum :: RealFloat a => a -> a -> a
- minNaN :: RealFloat a => a -> a -> a
- maxNaN :: RealFloat a => a -> a -> a

# IEEE type class

class RealFloat a => IEEE a where Source

IEEE floating point types.

Methods

infinity :: aSource

Infinity value.

minNormal :: aSource

The smallest representable positive normalized value.

maxFinite :: aSource

The largest representable finite value.

epsilon :: aSource

The smallest representalbe positive value `x` such that `1 + x /= 1`.

copySign :: a -> a -> aSource

`copySign x y` returns `x` with its sign changed to `y`'s.

identicalIEEE :: a -> a -> Bool Source

Return `True` if two values are exactly (bitwise) equal.

succIEEE :: a -> aSource

Return the next largest IEEE value (`Infinity` and `NaN` are unchanged).

predIEEE :: a -> aSource

Return the next smallest IEEE value (`-Infinity` and `NaN` are unchanged).

bisectIEEE :: a -> a -> aSource

Given two values with the same sign, return the value halfway between them on the IEEE number line. If the signs of the values differ or either is `NaN`, the value is undefined.

sameSignificandBits :: a -> a -> Int Source

The number of significand bits which are equal in the two arguments (equivalent to `feqrel` from the Tango Math library). The result is between `0` and ``floatDigits``.

nan :: aSource

Default `NaN` value.

nanWithPayload :: Word64 -> aSource

Quiet `NaN` value with a positive integer payload. Payload must be less than `maxNaNPayload`. Beware that while some platforms allow using `0` as a payload, this behavior is not portable.

maxNaNPayload :: a -> Word64 Source

Maximum `NaN` payload for type `a`.

nanPayload :: a -> Word64 Source

The payload stored in a `NaN` value. Undefined if the argument is not `NaN`.

Instances

IEEE Double |
IEEE Float |
IEEE CFloat |
IEEE CDouble |

# NaN-aware minimum and maximum

minNum :: RealFloat a => a -> a -> aSource

Return the minimum of two values; if one value is `NaN`, return the other. Prefer the first if both values are `NaN`.

maxNum :: RealFloat a => a -> a -> aSource

Return the maximum of two values; if one value is `NaN`, return the other. Prefer the first if both values are `NaN`.

minNaN :: RealFloat a => a -> a -> aSource

Return the minimum of two values; if one value is `NaN`, return it. Prefer the first if both values are `NaN`.

maxNaN :: RealFloat a => a -> a -> aSource

Return the maximum of two values; if one value is `NaN`, return it. Prefer the first if both values are `NaN`.