variable-precision-0.4: variable-precision floating point

PortabilityBangPatterns
Stabilityunstable
Maintainerclaude@mathr.co.uk
Safe HaskellSafe-Inferred

Numeric.VariablePrecision.Algorithms

Description

Implementations of various floating point algorithms. Accuracy has not been extensively verified, and termination has not been proven.

Everything assumes that floatRadix is 2. This is *not* checked.

Functions taking an accuracy parameter may fail to terminate if accuracy is too small. Accuracy is measured in least significant bits, similarly to '(=~=)'.

In this documentation, basic functionality denotes that methods used are from classes:

Further, basic RealFloat functionality denotes basic functionality with the addition of:

The intention behind the used functionality documentation is to help users decide when it is appropriate to use these generic implementations to implement instances.

Synopsis

Documentation

recodeFloat :: (RealFloat a, RealFloat b) => a -> bSource

Convert between generic RealFloat types more efficiently than realToFrac. Tries hard to preserve special values like infinities and negative zero, but any NaN payload is lost.

Uses only basic RealFloat functionality.

viaDouble :: (RealFloat a, RealFloat b) => (Double -> Double) -> a -> bSource

Lift a function from Double to generic RealFloat types.

(=~=) :: RealFloat a => a -> a -> Int -> BoolSource

Approximate equality. (a =~= b) c when adding the difference to the larger in magnitude changes at most c least significant mantissa bits.

Uses only basic RealFloat functionality.

genericRecipSource

Arguments

:: RealFloat a 
=> Int

accuracy

-> a 
-> a 

Compute a reciprocal using the Newton-Raphson division algorithm, as described in http://en.wikipedia.org/wiki/Division_%28digital%29#Newton.E2.80.93Raphson_division.

Uses only basic RealFloat functionality.

genericSqrtSource

Arguments

:: RealFloat a 
=> Int

accuracy

-> a 
-> a 

Compute a square root using Newton's method.

Uses basic RealFloat functionality and '(/)'.

genericExpSource

Arguments

:: RealFloat a 
=> Int

accuracy

-> a 
-> a 

Compute an exponential using power series.

Uses basic RealFloat functionality, '(/)' and recip.

genericLogSource

Arguments

:: RealFloat a 
=> Int

accuracy

-> a 
-> a 

Compute a logarithm.

See genericLog'' for algorithmic references.

Uses basic RealFloat functionality, sqrt and recip.

genericLog'Source

Arguments

:: RealFloat a 
=> Int

accuracy

-> a

log 2

-> a 
-> a 

Compute a logarithm using decomposition and a value for log 2.

See genericLog'' for algorithmic references.

Uses basic RealFloat functionality, sqrt, and recip.

genericLog2Source

Arguments

:: RealFloat a 
=> Int

accuracy

-> a 

Compute log 2.

See genericLog'' for algorithmic references.

Uses basic RealFloat functionality, sqrt and recip.

genericLog''Source

Arguments

:: RealFloat a 
=> Int

accuracy

-> a

value in [0.5,1)

-> a 

Compute a logarithm for a value in [0.5,1) using the AGM method as described in section 7 of The Logarithmic Constant: log 2 Xavier Gourdon and Pascal Sebah, May 18, 2010, http://numbers.computation.free.fr/Constants/Log2/log2.ps.

The precondition is not checked.

Uses basic RealFloat functionality, sqrt, and recip.

genericPiSource

Arguments

:: RealFloat a 
=> Int

accuracy

-> a 

Compute pi using the method described in section 8 of Multiple-precision zero-finding methods and the complexity of elementary function evaluation Richard P Brent, 1975 (revised May 30, 2010), http://arxiv.org/abs/1004.3412.

Uses basic RealFloat functionality, '(/)', and sqrt.

genericSinSource

Arguments

:: RealFloat a 
=> Int

accuracy

-> a

pi

-> a

x

-> a 

Compute sin using the method described in section 3 of Efficient multiple-precision evaluation of elementary functions David M Smith, 1989, http://digitalcommons.lmu.edu/math_fac/1/

Requires a value for pi.

Uses basic RealFloat functionality, '(/)', and sqrt.

genericPositiveZero :: RealFloat a => aSource

Special values implemented using basic RealFloat functionality.

genericNegativeZero :: RealFloat a => aSource

Special values implemented using basic RealFloat functionality.

genericPositiveInfinity :: RealFloat a => aSource

Special values implemented using basic RealFloat functionality.

genericNegativeInfinity :: RealFloat a => aSource

Special values implemented using basic RealFloat functionality.

genericNotANumber :: RealFloat a => aSource

Special values implemented using basic RealFloat functionality.

sameSign :: (Ord a, Num a) => a -> a -> BoolSource

Check if two numbers have the same sign. May give a nonsense result if an argument is NaN.