math-functions-0.3.1.0: Collection of tools for numeric computations

Copyright (c) 2011 Bryan O'Sullivan BSD3 bos@serpentine.com experimental portable None Haskell2010

Numeric.MathFunctions.Comparison

Description

Functions for approximate comparison of floating point numbers.

Approximate floating point comparison, based on Bruce Dawson's "Comparing floating point numbers": http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

Synopsis

Relative erros

Calculate relative error of two numbers:

$\frac{|a - b|}{\max(|a|,|b|)}$

It lies in [0,1) interval for numbers with same sign and (1,2] for numbers with different sign. If both arguments are zero or negative zero function returns 0. If at least one argument is transfinite it returns NaN

Arguments

 :: Double eps relative error should be in [0,1) range -> Double a -> Double b -> Bool

Check that relative error between two numbers a and b. If relativeError returns NaN it returns False.

Ulps-based comparison

addUlps :: Int -> Double -> Double #

Add N ULPs (units of least precision) to Double number.

Measure distance between two Doubles in ULPs (units of least precision). Note that it's different from abs (ulpDelta a b) since it returns correct result even when ulpDelta overflows.

Measure signed distance between two Doubles in ULPs (units of least precision). Note that unlike ulpDistance it can overflow.

>>> ulpDelta 1 (1 + m_epsilon)
1

Arguments

 :: Int Number of ULPs of accuracy desired. -> Double -> Double -> Bool

Compare two Double values for approximate equality, using Dawson's method.

The required accuracy is specified in ULPs (units of least precision). If the two numbers differ by the given number of ULPs or less, this function returns True.