hmpfr-0.4.0.1: Haskell binding to the MPFR library

Copyright(c) Aleš Bizjak
LicenseBSD3
Maintainermikkonecny@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell98

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

data MPFR Source #

Instances

Storable MPFR Source # 

Methods

sizeOf :: MPFR -> Int #

alignment :: MPFR -> Int #

peekElemOff :: Ptr MPFR -> Int -> IO MPFR #

pokeElemOff :: Ptr MPFR -> Int -> MPFR -> IO () #

peekByteOff :: Ptr b -> Int -> IO MPFR #

pokeByteOff :: Ptr b -> Int -> MPFR -> IO () #

peek :: Ptr MPFR -> IO MPFR #

poke :: Ptr MPFR -> MPFR -> IO () #

data Precision Source #

Instances

Enum Precision Source # 
Eq Precision Source # 
Integral Precision Source # 
Num Precision Source # 
Ord Precision Source # 
Real Precision Source # 
Show Precision Source # 

type Exp = Int64 Source #

Assignment functions

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

int2w :: RoundMode -> Precision -> Word -> Int -> MPFR Source #

x * 2 ^ y

int2i :: RoundMode -> Precision -> Int -> Int -> MPFR Source #

x * 2 ^ y

stringToMPFR Source #

Arguments

:: RoundMode 
-> Precision 
-> Word

Base

-> String 
-> MPFR 

stringToMPFR_ Source #

Arguments

:: RoundMode 
-> Precision 
-> Word

Base

-> String 
-> (MPFR, Int) 

strtofr Source #

Arguments

:: RoundMode 
-> Precision 
-> Word

base

-> String 
-> (MPFR, String) 

strtofr_ Source #

Arguments

:: RoundMode 
-> Precision 
-> Word

base

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

fromString :: String -> Precision -> Word -> MPFR Source #

stringToMPFR with default rounding to Near.

Conversion functions

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

mpfrToString Source #

Arguments

:: RoundMode 
-> Word

number of decimals

-> Word

base

-> MPFR 
-> (String, Exp) 

toStringExp Source #

Arguments

:: Word

number of digits

-> MPFR 
-> String 

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

toString :: Word -> MPFR -> String Source #

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.

sincos Source #

Arguments

:: RoundMode 
-> Precision

precision to compute sin

-> Precision

precision to compute cos

-> MPFR 
-> (MPFR, MPFR)

return (sin x, cos x)

sinhcosh Source #

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

modf Source #

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.

urandomb :: Ptr GmpRandState -> Precision -> MPFR Source #

getMantissa :: MPFR -> Integer Source #

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