hmpfr-0.3.1: Haskell binding to MPFR library

Portabilitynon-portable
Stabilityexperimental
Maintainerales.bizjak0@gmail.com

Data.Number.MPFR

Contents

Description

This module exports a pure interface to the MPFR library functions. Functions return new MPFR structures instead of modifying existing ones and so all functions which produce a new MPFR structure take one more parameter than their original C counterparts. This parameter, Precision, is the precision of the resulting MPFR.

This is naturally slower than modifying in-place, especially when dealing with lower precisions, so a "mutable" interface is provided in Data.Number.MPFR.Mutable module.

Naming conventions

  • functions ending with _ (underscore) usually return a pair (MPFR, Int), where Int is a return value of a corresponding mpfr_ function. See the MPFR manual for a description of return values.
  • the same functions without the _ return just the MPFR.
  • mpfr_ prefix in functions is removed
  • _ui and ui_ in function becomes w (stands for Word). For example mpfr_sub_ui becomes subw and mpfr_ui_sub becomes wsub.
  • si_ and _si in functions becomes i (stands for Int). For example mpfr_sub_si becomes subi and mpfr_si_sub becomes isub.
  • comparison functions which have _p appended loose it. For example mpfr_less_p becomes less.

Instances

Eq
  • NaN /= NaN,
  • Infinity = Infinity,
  • -Infinity = -Infinity
  • otherwise normal comparison
Ord
  • compare NaN _ = GT
  • compare _ NaN = GT
  • infinity < _ = False
  • -infinity > _ = False
  • NaN [<,>,>=,<=] _ = False

This mimics the behaviour of built in Haskell Float and Double.

If you need instances of numeric typeclasses import one of the Data.Number.MPFR.Instances.* modules.

Synopsis

Documentation

Assignment functions

See http://www.mpfr.org/mpfr-current/mpfr.html#Assignment-Functions documentation on particular functions.

int2w :: RoundMode -> Precision -> Word -> Int -> MPFRSource

x * 2 ^ y

int2i :: RoundMode -> Precision -> Int -> Int -> MPFRSource

x * 2 ^ y

stringToMPFRSource

Arguments

:: RoundMode 
-> Precision 
-> Word

Base

-> String 
-> MPFR 

stringToMPFR_Source

Arguments

:: RoundMode 
-> Precision 
-> Word

Base

-> String 
-> (MPFR, Int) 

strtofrSource

Arguments

:: RoundMode 
-> Precision 
-> Word

base

-> String 
-> (MPFR, String) 

strtofr_Source

Arguments

:: RoundMode 
-> Precision 
-> Word

base

-> String 
-> (MPFR, String, Int) 

fromString :: String -> Precision -> Word -> MPFRSource

stringToMPFR with default rounding to Near.

Conversion functions

See http://www.mpfr.org/mpfr-current/mpfr.html#Conversion-Functions documentation on particular functions.

mpfrToStringSource

Arguments

:: RoundMode 
-> Word

number of decimals

-> Word

base

-> MPFR 
-> (String, Exp) 

toStringExpSource

Arguments

:: Word

number of digits

-> MPFR 
-> String 

Output a string in base 10 rounded to Near in exponential form.

toString :: Word -> MPFR -> StringSource

Output a string in base 10 rounded to Near. The difference from toStringExp is that it won't output in exponential form if it is sensible to do so.

Basic arithmetic functions

For documentation on particular functions see http://www.mpfr.org/mpfr-current/mpfr.html#Basic-Arithmetic-Functions.

Comparison functions

For documentation on particular functions see http://www.mpfr.org/mpfr-current/mpfr.html#Comparison-Functions

Special functions

For documentation on particular functions see http://www.mpfr.org/mpfr-current/mpfr.html#Special-Functions.

sincosSource

Arguments

:: RoundMode 
-> Precision

precision to compute sin

-> Precision

precision to compute cos

-> MPFR 
-> (MPFR, MPFR)

return (sin x, cos x)

sinhcoshSource

Arguments

:: RoundMode 
-> Precision

precision to compute sin

-> Precision

precision to compute cos

-> MPFR 
-> (MPFR, MPFR)

return (sin x, cos x)

sincos_Source

Arguments

:: RoundMode 
-> Precision

precision to compute sin

-> Precision

precision to compute cos

-> MPFR 
-> (MPFR, MPFR, Int) 

sinhcosh_Source

Arguments

:: RoundMode 
-> Precision

precision to compute sinh

-> Precision

precision to compute cosh

-> MPFR 
-> (MPFR, MPFR, Int) 

Integer related functions

modfSource

Arguments

:: RoundMode 
-> Precision

precision to integral part

-> Precision

precision to fractional part

-> MPFR 
-> (MPFR, MPFR)

return (integral part, fractional part)

modf_Source

Arguments

:: RoundMode 
-> Precision

precision to compute integral part

-> Precision

precision to compute fractional part

-> MPFR 
-> (MPFR, MPFR, Int) 

Miscellaneous functions

For documentation on particular functions see http://www.mpfr.org/mpfr-current/mpfr.html#Miscellaneous-Functions.

getMantissa :: MPFR -> IntegerSource

getMantissa and getExp return values such that

 d = getMantissa d * 2^(getExp d - ceiling ((getPrec d) / bitsPerMPLimb)* bitsPerMPLimb )

In case of 0, NaN or +-Inf getMantissa will return 0