dimensional-1.6.1: Statically checked physical dimensions

Copyright | Copyright (C) 2006-2018 Bjorn Buckwalter
License | BSD3
Maintainer | bjorn@buckwalter.se
Stability | Stable
Safe Haskell | None
Language | Haskell2010

Numeric.Units.Dimensional.Float

Contents

- Lifted Predicates from `RealFloat`
- Convenience Functions
- Lifted Functions from Numeric.IEEE
  - Values
  - Arithmetic
  - NaN with Payload
  - Comparisons

Description

Defines convenience functions for inspecting and manipulating quantities with `RealFloat` floating-point representations.

The dimensionally-typed versions of functions from Patrick Perry's ieee754 package copy that packages API as closely as possible, by permission. In turn they are based on the `tango` math library for the D language.

Synopsis

- isDenormalized :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Bool
- isInfinite :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Bool
- isNaN :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Bool
- isNegativeZero :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Bool
- isFiniteNumber :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Bool
- scaleFloat :: forall a (d :: Dimension). RealFloat a => Int -> Quantity d a -> Quantity d a
- infinity :: forall a (d :: Dimension). IEEE a => Quantity d a
- minNormal :: forall a (d :: Dimension). IEEE a => Quantity d a
- maxFinite :: forall a (d :: Dimension). IEEE a => Quantity d a
- epsilon :: IEEE a => Dimensionless a
- nan :: forall a (d :: Dimension). IEEE a => Quantity d a
- predIEEE :: forall a (d :: Dimension). IEEE a => Quantity d a -> Quantity d a
- succIEEE :: forall a (d :: Dimension). IEEE a => Quantity d a -> Quantity d a
- bisectIEEE :: forall a (d :: Dimension). IEEE a => Quantity d a -> Quantity d a -> Quantity d a
- copySign :: forall a (d :: Dimension). IEEE a => Quantity d a -> Quantity d a -> Quantity d a
- nanWithPayload :: forall a (d :: Dimension). IEEE a => Word64 -> Quantity d a
- nanPayload :: forall a (d :: Dimension). IEEE a => Quantity d a -> Word64
- maxNaNPayload :: IEEE a => a -> Word64
- identicalIEEE :: forall a (d :: Dimension). IEEE a => Quantity d a -> Quantity d a -> Bool
- minNum :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Quantity d a -> Quantity d a
- maxNum :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Quantity d a -> Quantity d a
- minNaN :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Quantity d a -> Quantity d a
- maxNaN :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Quantity d a -> Quantity d a

# Lifted Predicates from `RealFloat`

isDenormalized :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Bool Source #

`True` if the representation of the argument is too small to be represented in normalized format.

isInfinite :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Bool Source #

`True` if the representation of the argument is an IEEE infinity or negative infinity.

    >>> isInfinite (_1 / _0)
    True

    >>> isInfinite (42 *~ micro farad)
    False

isNaN :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Bool Source #

`True` if the representation of the argument is an IEEE "not-a-number" (NaN) value.

    >>> isNaN _3
    False

    >>> isNaN (_1 / _0)
    False

    >>> isNaN (asin _4)
    True

isNegativeZero :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Bool Source #

`True` if the representation of the argument is an IEEE negative zero.

    >>> isNegativeZero _0
    False

    >>> isNegativeZero $ (-1e-200 *~ one) * (1e-200 *~ one)
    True

# Convenience Functions

isFiniteNumber :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Bool Source #

`True` if the representation of the argument is a number and is not infinite.

    >>> isFiniteNumber (_1 / _0)
    False

    >>> isFiniteNumber (_0 / _0)
    False

    >>> isFiniteNumber (_3 / _2)
    True

scaleFloat :: forall a (d :: Dimension). RealFloat a => Int -> Quantity d a -> Quantity d a Source #

Multiplies a floating-point quantity by an integer power of the radix of the representation type.

Use `floatRadix` to determine the radix.

    >>> let x = 3 *~ meter
    >>> scaleFloat 3 x
    24.0 m

# Lifted Functions from Numeric.IEEE

## Values

infinity :: forall a (d :: Dimension). IEEE a => Quantity d a Source #

An infinite floating-point quantity.

minNormal :: forall a (d :: Dimension). IEEE a => Quantity d a Source #

The smallest representable positive quantity whose representation is normalized.

maxFinite :: forall a (d :: Dimension). IEEE a => Quantity d a Source #

The largest representable finite floating-point quantity.

epsilon :: IEEE a => Dimensionless a Source #

The smallest positive value `x` such that `_1 + x` is representable.

nan :: forall a (d :: Dimension). IEEE a => Quantity d a Source #

Default `NaN` quantity.

## Arithmetic

predIEEE :: forall a (d :: Dimension). IEEE a => Quantity d a -> Quantity d a Source #

Return the next smallest representable floating-point quantity (`Infinity` and `NaN` are unchanged).

succIEEE :: forall a (d :: Dimension). IEEE a => Quantity d a -> Quantity d a Source #

Return the next largest representable floating-point quantity (`Infinity` and `NaN` are unchanged).

bisectIEEE :: forall a (d :: Dimension). IEEE a => Quantity d a -> Quantity d a -> Quantity d a Source #

Given two floating-point quantities with the same sign, return the quantity whose representation is halfway between their representations on the IEEE number line. If the signs of the values differ or either is `NaN`, the value is undefined.

copySign :: forall a (d :: Dimension). IEEE a => Quantity d a -> Quantity d a -> Quantity d a Source #

`copySign x y` returns the quantity `x` with its sign changed to match that of `y`.

## NaN with Payload

nanWithPayload :: forall a (d :: Dimension). IEEE a => Word64 -> Quantity d a Source #

Quiet `NaN` quantity with a positive integer payload. Payload must be less than `maxNaNPayload` of the representation type.

Beware that while some platforms allow using 0 as a payload, this behavior is not portable.

nanPayload :: forall a (d :: Dimension). IEEE a => Quantity d a -> Word64 Source #

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

maxNaNPayload :: IEEE a => a -> Word64 Source #

Maximum `NaN` payload for type `a`.

## Comparisons

identicalIEEE :: forall a (d :: Dimension). IEEE a => Quantity d a -> Quantity d a -> Bool Source #

Return `True` if two floating-point quantities are exactly (bitwise) equal.

minNum :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Quantity d a -> Quantity d a Source #

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

maxNum :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Quantity d a -> Quantity d a Source #

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

minNaN :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Quantity d a -> Quantity d a Source #

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

maxNaN :: forall a (d :: Dimension). RealFloat a => Quantity d a -> Quantity d a -> Quantity d a Source #

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