libBF-0.6.8: A binding to the libBF library.

Safe Haskell | Trustworthy
Language | Haskell2010

LibBF

Contents

- Constants
- Conversions
- Predicates
- Arithmetic
- Rounding
- Mutability
- Limits
- Configuration

Description

Computation with high-precision floats.

Synopsis

- data BigFloat
- bfPosZero :: BigFloat
- bfNegZero :: BigFloat
- bfPosInf :: BigFloat
- bfNegInf :: BigFloat
- bfNaN :: BigFloat
- bfFromWord :: Word64 -> BigFloat
- bfFromInt :: Int64 -> BigFloat
- bfFromDouble :: Double -> BigFloat
- bfFromInteger :: Integer -> BigFloat
- bfFromString :: Int -> BFOpts -> String -> (BigFloat, Status)
- bfToDouble :: RoundMode -> BigFloat -> (Double, Status)
- bfToString :: Int -> ShowFmt -> BigFloat -> String
- bfToRep :: BigFloat -> BFRep
- data BFRep
  - = BFRep !Sign !BFNum
  - | BFNaN
- data BFNum
  - = Zero
  - | Num Integer !Int64
  - | Inf
- bfFromBits :: BFOpts -> Integer -> BigFloat
- bfToBits :: BFOpts -> BigFloat -> Integer
- bfIsFinite :: BigFloat -> Bool
- bfIsInf :: BigFloat -> Bool
- bfIsZero :: BigFloat -> Bool
- bfIsNaN :: BigFloat -> Bool
- bfIsNormal :: BFOpts -> BigFloat -> Bool
- bfIsSubnormal :: BFOpts -> BigFloat -> Bool
- bfCompare :: BigFloat -> BigFloat -> Ordering
- bfSign :: BigFloat -> Maybe Sign
- bfExponent :: BigFloat -> Maybe Int64
- bfIsPos :: BigFloat -> Bool
- bfIsNeg :: BigFloat -> Bool
- data Sign
  - = Neg
  - | Pos
- bfNeg :: BigFloat -> BigFloat
- bfAbs :: BigFloat -> BigFloat
- bfAdd :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)
- bfSub :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)
- bfMul :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)
- bfDiv :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)
- bfRem :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)
- bfFMA :: BFOpts -> BigFloat -> BigFloat -> BigFloat -> (BigFloat, Status)
- bfMulWord :: BFOpts -> BigFloat -> Word64 -> (BigFloat, Status)
- bfMulInt :: BFOpts -> BigFloat -> Int64 -> (BigFloat, Status)
- bfMul2Exp :: BFOpts -> BigFloat -> Int -> (BigFloat, Status)
- bfSqrt :: BFOpts -> BigFloat -> (BigFloat, Status)
- bfPow :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)
- bfRoundFloat :: BFOpts -> BigFloat -> (BigFloat, Status)
- bfRoundInt :: RoundMode -> BigFloat -> (BigFloat, Status)
- bfUnsafeThaw :: BigFloat -> BF
- bfUnsafeFreeze :: BF -> BigFloat
- module LibBF.Opts

# Constants

data BigFloat Source #

Arbitrary precision floating point numbers.

#### Instances

Instances details

NFData BigFloat Source # |
Instance details Defined in LibBF Methods rnf :: BigFloat -> () Source #
Data BigFloat Source # |

Instance details

Defined in LibBF

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> BigFloat -> c BigFloat Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c BigFloat Source #

toConstr :: BigFloat -> Constr Source #

dataTypeOf :: BigFloat -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c BigFloat) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BigFloat) Source #

gmapT :: (forall b. Data b => b -> b) -> BigFloat -> BigFloat Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BigFloat -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BigFloat -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> BigFloat -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> BigFloat -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> BigFloat -> m BigFloat Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> BigFloat -> m BigFloat Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> BigFloat -> m BigFloat Source #

Show BigFloat Source # |
Instance details Defined in LibBF Methods showsPrec :: Int -> BigFloat -> ShowS Source # show :: BigFloat -> String Source # showList :: [BigFloat] -> ShowS Source #
Eq BigFloat Source # | IEEE 754 equality
Instance details Defined in LibBF Methods (==) :: BigFloat -> BigFloat -> Bool Source # (/=) :: BigFloat -> BigFloat -> Bool Source #
Ord BigFloat Source # | IEEE 754 comparisons
Instance details Defined in LibBF Methods compare :: BigFloat -> BigFloat -> Ordering Source # (<) :: BigFloat -> BigFloat -> Bool Source # (<=) :: BigFloat -> BigFloat -> Bool Source # (>) :: BigFloat -> BigFloat -> Bool Source # (>=) :: BigFloat -> BigFloat -> Bool Source # max :: BigFloat -> BigFloat -> BigFloat Source # min :: BigFloat -> BigFloat -> BigFloat Source #
Hashable BigFloat Source # |
Instance details Defined in LibBF Methods hashWithSalt :: Int -> BigFloat -> Int Source # hash :: BigFloat -> Int Source #

bfPosZero :: BigFloat Source #

Positive zero.

bfNegZero :: BigFloat Source #

Negative zero.

bfPosInf :: BigFloat Source #

Positive infinity.

bfNegInf :: BigFloat Source #

Negative infinity.

bfNaN :: BigFloat Source #

Not-a-number.

# Conversions

bfFromWord :: Word64 -> BigFloat Source #

A floating point number corresponding to the given word.

bfFromInt :: Int64 -> BigFloat Source #

A floating point number corresponding to the given int.

bfFromDouble :: Double -> BigFloat Source #

A floating point number corresponding to the given double.

bfFromInteger :: Integer -> BigFloat Source #

A floating point number corresponding to the given integer.

bfFromString Source #

Arguments

:: Int | Base
-> BFOpts |
-> String |
-> (BigFloat, Status) |

Parse a number from the given string. Returns @NaN` if the string does not correspond to a number we recognize.

bfToDouble :: RoundMode -> BigFloat -> (Double, Status) Source #

Constant to a `Double`

bfToString Source #

Arguments

:: Int | Base
-> ShowFmt |
-> BigFloat |
-> String |

Render as a `String`, using the given settings.

bfToRep :: BigFloat -> BFRep Source #

The float as an exponentiated `Integer`.

data BFRep Source #

An explicit representation for big nums.

Constructors

BFRep !Sign !BFNum | A signed number
BFNaN | Not a number

#### Instances

Instances details

Data BFRep Source # |

Instance details

Defined in LibBF.Mutable

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> BFRep -> c BFRep Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c BFRep Source #

toConstr :: BFRep -> Constr Source #

dataTypeOf :: BFRep -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c BFRep) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BFRep) Source #

gmapT :: (forall b. Data b => b -> b) -> BFRep -> BFRep Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BFRep -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BFRep -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> BFRep -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> BFRep -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> BFRep -> m BFRep Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> BFRep -> m BFRep Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> BFRep -> m BFRep Source #

Show BFRep Source # |
Instance details Defined in LibBF.Mutable Methods showsPrec :: Int -> BFRep -> ShowS Source # show :: BFRep -> String Source # showList :: [BFRep] -> ShowS Source #
Eq BFRep Source # |
Instance details Defined in LibBF.Mutable Methods (==) :: BFRep -> BFRep -> Bool Source # (/=) :: BFRep -> BFRep -> Bool Source #
Ord BFRep Source # |
Instance details Defined in LibBF.Mutable Methods compare :: BFRep -> BFRep -> Ordering Source # (<) :: BFRep -> BFRep -> Bool Source # (<=) :: BFRep -> BFRep -> Bool Source # (>) :: BFRep -> BFRep -> Bool Source # (>=) :: BFRep -> BFRep -> Bool Source # max :: BFRep -> BFRep -> BFRep Source # min :: BFRep -> BFRep -> BFRep Source #
Hashable BFRep Source # |
Instance details Defined in LibBF.Mutable Methods hashWithSalt :: Int -> BFRep -> Int Source # hash :: BFRep -> Int Source #

data BFNum Source #

Representations for unsigned floating point numbers.

Constructors

Zero | zero

Num Integer !Int64

    x * 2 ^ y

Inf | infinity

#### Instances

Instances details

Data BFNum Source # |

Instance details

Defined in LibBF.Mutable

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> BFNum -> c BFNum Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c BFNum Source #

toConstr :: BFNum -> Constr Source #

dataTypeOf :: BFNum -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c BFNum) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BFNum) Source #

gmapT :: (forall b. Data b => b -> b) -> BFNum -> BFNum Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BFNum -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BFNum -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> BFNum -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> BFNum -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> BFNum -> m BFNum Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> BFNum -> m BFNum Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> BFNum -> m BFNum Source #

Show BFNum Source # |
Instance details Defined in LibBF.Mutable Methods showsPrec :: Int -> BFNum -> ShowS Source # show :: BFNum -> String Source # showList :: [BFNum] -> ShowS Source #
Eq BFNum Source # |
Instance details Defined in LibBF.Mutable Methods (==) :: BFNum -> BFNum -> Bool Source # (/=) :: BFNum -> BFNum -> Bool Source #
Ord BFNum Source # |
Instance details Defined in LibBF.Mutable Methods compare :: BFNum -> BFNum -> Ordering Source # (<) :: BFNum -> BFNum -> Bool Source # (<=) :: BFNum -> BFNum -> Bool Source # (>) :: BFNum -> BFNum -> Bool Source # (>=) :: BFNum -> BFNum -> Bool Source # max :: BFNum -> BFNum -> BFNum Source # min :: BFNum -> BFNum -> BFNum Source #
Hashable BFNum Source # |
Instance details Defined in LibBF.Mutable Methods hashWithSalt :: Int -> BFNum -> Int Source # hash :: BFNum -> Int Source #

bfFromBits Source #

Arguments

:: BFOpts |
-> Integer | Raw bits
-> BigFloat |

Make a float using "raw" bits representing the bitvector representation of a floating-point value with the exponent and precision bits given by the options.

bfToBits :: BFOpts -> BigFloat -> Integer Source #

Turn a float into raw bits. `NaN` is represented as a positive "quiet" `NaN` (most significant bit in the significand is set, the rest of it is 0).

# Predicates

bfIsFinite :: BigFloat -> Bool Source #

Is this a finite (i.e., non-infinite, non NaN) number.

bfIsInf :: BigFloat -> Bool Source #

Is this value infinite

bfIsZero :: BigFloat -> Bool Source #

Is this value a zero.

bfIsNaN :: BigFloat -> Bool Source #

Is this value NaN.

bfIsNormal :: BFOpts -> BigFloat -> Bool Source #

This is a "normal" number, which means it is not a NaN, not a zero, not infinite, and not subnormal.

bfIsSubnormal :: BFOpts -> BigFloat -> Bool Source #

This number is "subnormal", which means it is among the smallest representable numbers for the given precision and exponent bits. These numbers differ from "normal" numbers in that they do not use an implicit leading 1 bit in the binary representation.

bfCompare :: BigFloat -> BigFloat -> Ordering Source #

Compare the two numbers. The special values are ordered like this:

- -0 < 0
- NaN == NaN
- NaN is larger than all other numbers

Note that this differs from `(<=)`

bfSign :: BigFloat -> Maybe Sign Source #

Get the sign of a number. Returns `Nothing` if the number is `NaN`.

bfExponent :: BigFloat -> Maybe Int64 Source #

Get the exponent for the given number. Infinity, zero and NaN do not have an exponent.

bfIsPos :: BigFloat -> Bool Source #

Is this value positive

bfIsNeg :: BigFloat -> Bool Source #

Is this value negative

data Sign Source #

Indicates if a number is positive or negative.

Constructors

Neg | Negative
Pos | Positive

#### Instances

Instances details

Data Sign Source # |

Instance details

Defined in LibBF.Mutable

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Sign -> c Sign Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Sign Source #

toConstr :: Sign -> Constr Source #

dataTypeOf :: Sign -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Sign) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Sign) Source #

gmapT :: (forall b. Data b => b -> b) -> Sign -> Sign Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sign -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Sign -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Sign -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Sign -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Sign -> m Sign Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Sign -> m Sign Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Sign -> m Sign Source #

Show Sign Source # |
Instance details Defined in LibBF.Mutable Methods showsPrec :: Int -> Sign -> ShowS Source # show :: Sign -> String Source # showList :: [Sign] -> ShowS Source #
Eq Sign Source # |
Instance details Defined in LibBF.Mutable Methods (==) :: Sign -> Sign -> Bool Source # (/=) :: Sign -> Sign -> Bool Source #
Ord Sign Source # |
Instance details Defined in LibBF.Mutable Methods compare :: Sign -> Sign -> Ordering Source # (<) :: Sign -> Sign -> Bool Source # (<=) :: Sign -> Sign -> Bool Source # (>) :: Sign -> Sign -> Bool Source # (>=) :: Sign -> Sign -> Bool Source # max :: Sign -> Sign -> Sign Source # min :: Sign -> Sign -> Sign Source #

# Arithmetic

bfNeg :: BigFloat -> BigFloat Source #

Negate a floating point number.

bfAbs :: BigFloat -> BigFloat Source #

Compute the absolute value of a number.

bfAdd :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status) Source #

Add two numbers useing the given options.

bfSub :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status) Source #

Subtract two numbers useing the given options.

bfMul :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status) Source #

Multiply two numbers using the given options.

bfDiv :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status) Source #

Divide two numbers useing the given options.

bfRem :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status) Source #

Compute the remainder `x - y * n` where `n` is the integer nearest to `x/y` (with ties broken to even values of `n`).

bfFMA :: BFOpts -> BigFloat -> BigFloat -> BigFloat -> (BigFloat, Status) Source #

Compute the fused-multiply-add `(x*y)+z`

bfMulWord :: BFOpts -> BigFloat -> Word64 -> (BigFloat, Status) Source #

Multiply a number and a word, using the given options.

bfMulInt :: BFOpts -> BigFloat -> Int64 -> (BigFloat, Status) Source #

Multiply a number and an int, using the given options.

bfMul2Exp :: BFOpts -> BigFloat -> Int -> (BigFloat, Status) Source #

Multiply a number by `2^e`.

bfSqrt :: BFOpts -> BigFloat -> (BigFloat, Status) Source #

Square root of two numbers useing the given options.

bfPow :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status) Source #

Exponentiate a word to a positive integer power.

# Rounding

bfRoundFloat :: BFOpts -> BigFloat -> (BigFloat, Status) Source #

Round to a float matching the input parameters.

bfRoundInt :: RoundMode -> BigFloat -> (BigFloat, Status) Source #

Round to an integer using the given rounding mode.

# Mutability

bfUnsafeThaw :: BigFloat -> BF Source #

Make a number mutable. WARNING: This does not copy the number, so it could break referential transperancy.

bfUnsafeFreeze :: BF -> BigFloat Source #

Make a number immutable. WARNING: This does not copy the number, so it could break referential transperancy.

# Limits

# Configuration

module LibBF.Opts