math-extras-0.1.1.0: A variety of mathematical utilities

MaintainerZiyang Liu <free@cofree.io>
Safe HaskellNone
LanguageHaskell2010

Math.Extras.Double

Contents

Description

Arithmetic on doubles. Some functions use more general types than Double.

Synopsis

Constant double values

positiveInfinity :: Double Source #

A constant holding the positive infinity of type Double.

negativeInfinity :: Double Source #

A constant holding the negative infinity of type Double.

nan :: Double Source #

A constant holding a NaN value of type Double.

Fuzzy comparison

fuzzyEq :: Tolerance -> Double -> Double -> Bool Source #

Returns True if the difference of the two numbers are no more than abs(tolerance).

fuzzyEq tolerance is reflexive and symmetric, but not transitive unless tolerance is zero, positiveInfinity, negativeInfinity, or NaN.

fuzzyCompare :: Tolerance -> Double -> Double -> Ordering Source #

Compare two Doubles with a tolerance.

If fuzzyEq tolerance x y then fuzzyCompare tolerance x y == EQ; otherwise fuzzyCompare tolerance x y == compare x y.

(~=) :: Double -> Double -> Bool Source #

(~=) is equivalent to fuzzyEq 1.0e-6.

(/~=) :: Double -> Double -> Bool Source #

x /~= y is equivalent to not (x ~= y).

Rounding

data RoundingMode Source #

Constructors

Up

Round away from 0

Down

Round towards 0

Ceiling

Round towards positive infinity

Floor

Round towards negative infinity

HalfUp

Round towards nearest integer; round Up in case of a tie

HalfDown

Round towards nearest integer; round Down in case of a tie

HalfEven

Round towards nearest integer; round towards the even neighbor in case of a tie

roundToInteger :: RoundingMode -> Double -> Integer Source #

Round a Double to an Integer using the specified RoundingMode.

saturatedRound :: forall a. (Bounded a, Integral a) => RoundingMode -> Double -> a Source #

Round a Double to an integral number using the specified RoundingMode. Returns maxBound and minBound in case of overflow and underflow, respectively.

Predicates

isFinite :: RealFloat a => a -> Bool Source #

Returns False for NaN and infinity, and True otherwise.

isInteger :: (Eq a, Num a, RealFloat a) => a -> Bool Source #

Returns True if the input represents an integer.

Conversion

toInt64RawBits :: Double -> Int64 Source #

Returns an Int64 with the same bit representation as the given Double.

toWord64RawBits :: Double -> Word64 Source #

Returns a Word64 with the same bit representation as the given Double.

fromInt64RawBits :: Int64 -> Double Source #

Returns a Double with the same bit representation as the given Int64.

fromWord64RawBits :: Word64 -> Double Source #

Returns a Double with the same bit representation as the given Word64.