libBF-0.6.8: A binding to the libBF library.

Safe Haskell | None
Language | Haskell2010

LibBF.Mutable

Contents

- Allocation
- Assignment
- Queries and Comparisons
- Arithmetic
- Convert from a number
- Configuration

Description

Mutable big-float computation.

Synopsis

- newContext :: IO BFContext
- data BFContext
- new :: BFContext -> IO BF
- data BF
- setNaN :: BF -> IO ()
- setZero :: Sign -> BF -> IO ()
- setInf :: Sign -> BF -> IO ()
- data Sign
  - = Neg
  - | Pos
- setWord :: Word64 -> BF -> IO ()
- setInt :: Int64 -> BF -> IO ()
- setDouble :: Double -> BF -> IO ()
- setInteger :: Integer -> BF -> IO ()
- setBF :: BF -> BF -> IO ()
- setString :: Int -> BFOpts -> String -> BF -> IO (Status, Int, Bool)
- cmpEq :: BF -> BF -> IO Bool
- cmpLT :: BF -> BF -> IO Bool
- cmpLEQ :: BF -> BF -> IO Bool
- cmpAbs :: BF -> BF -> IO Ordering
- cmp :: BF -> BF -> IO Ordering
- getSign :: BF -> IO (Maybe Sign)
- getExp :: BF -> IO (Maybe Int64)
- isFinite :: BF -> IO Bool
- isInf :: BF -> IO Bool
- isNaN :: BF -> IO Bool
- isZero :: BF -> IO Bool
- fneg :: BF -> IO ()
- fadd :: BFOpts -> BF -> BF -> BF -> IO Status
- faddInt :: BFOpts -> BF -> Int64 -> BF -> IO Status
- fsub :: BFOpts -> BF -> BF -> BF -> IO Status
- fmul :: BFOpts -> BF -> BF -> BF -> IO Status
- fmulInt :: BFOpts -> BF -> Int64 -> BF -> IO Status
- fmulWord :: BFOpts -> BF -> Word64 -> BF -> IO Status
- fmul2Exp :: BFOpts -> Int -> BF -> IO Status
- ffma :: BFOpts -> BF -> BF -> BF -> BF -> IO Status
- fdiv :: BFOpts -> BF -> BF -> BF -> IO Status
- frem :: BFOpts -> BF -> BF -> BF -> IO Status
- fsqrt :: BFOpts -> BF -> BF -> IO Status
- fpow :: BFOpts -> BF -> BF -> BF -> IO Status
- fround :: BFOpts -> BF -> IO Status
- frint :: RoundMode -> BF -> IO Status
- toDouble :: RoundMode -> BF -> IO (Double, Status)
- toString :: Int -> ShowFmt -> BF -> IO String
- toRep :: BF -> IO BFRep
- data BFRep
  - = BFRep !Sign !BFNum
  - | BFNaN
- data BFNum
  - = Zero
  - | Num Integer !Int64
  - | Inf
- module LibBF.Opts
- toChunks :: Integer -> [LimbT]

# Allocation

newContext :: IO BFContext Source #

Allocate a new numeric context.

data BFContext Source #

State of the current computation context.

new :: BFContext -> IO BF Source #

Allocate a new number. Starts off as zero.

data BF Source #

A mutable high precision floating point number.

# Assignment

setNaN :: BF -> IO () Source #

Assign `NaN` to the number.

setZero :: Sign -> BF -> IO () Source #

Assign a zero to the number.

setInf :: Sign -> BF -> IO () Source #

Assign an infinty to the number.

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 #

setWord :: Word64 -> BF -> IO () Source #

Assign from a word

setInt :: Int64 -> BF -> IO () Source #

Assign from an int

setDouble :: Double -> BF -> IO () Source #

Assign from a double

setInteger :: Integer -> BF -> IO () Source #

Set an integer. If the integer is larger than the primitive types, this does repreated Int64 additions and multiplications.

setBF Source #

Arguments

:: BF |
-> BF | This number is changed
-> IO () |

Assign from another number.

setString :: Int -> BFOpts -> String -> BF -> IO (Status, Int, Bool) Source #

Set the value to the float parsed out of the given string. * The radix should not exceed `maxRadix`. * Sets the number to `NaN` on failure. * Assumes that characters are encoded with a single byte each. * Retruns: - Status for the conversion - How many bytes we consumed - Did we consume the whole input

# Queries and Comparisons

cmpEq :: BF -> BF -> IO Bool Source #

Check if the two numbers are equal.

cmpLT :: BF -> BF -> IO Bool Source #

Check if the first number is strictly less than the second.

cmpLEQ :: BF -> BF -> IO Bool Source #

Check if the first number is less than, or equal to, the second.

cmpAbs :: BF -> BF -> IO Ordering Source #

Compare the absolute values of the two numbers. See also `cmp`.

cmp :: BF -> BF -> IO Ordering Source #

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

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

getSign :: BF -> IO (Maybe Sign) Source #

Returns `Nothing` for `NaN`.

getExp :: BF -> IO (Maybe Int64) Source #

Get the exponent of the number. Returns `Nothing` for inifinity, zero and NaN.

isFinite :: BF -> IO Bool Source #

Check if the number is "normal", i.e. (not infinite or NaN)

isInf :: BF -> IO Bool Source #

Check if the given numer is infinite.

isNaN :: BF -> IO Bool Source #

Check if the number is NaN

isZero :: BF -> IO Bool Source #

Check if the given number is a zero.

# Arithmetic

fneg :: BF -> IO () Source #

Negate the number.

fadd :: BFOpts -> BF -> BF -> BF -> IO Status Source #

Add two numbers, using the given settings, and store the result in the last.

faddInt :: BFOpts -> BF -> Int64 -> BF -> IO Status Source #

Add a number and an int64 and store the result in the last.

fsub :: BFOpts -> BF -> BF -> BF -> IO Status Source #

Subtract two numbers, using the given settings, and store the result in the last.

fmul :: BFOpts -> BF -> BF -> BF -> IO Status Source #

Multiply two numbers, using the given settings, and store the result in the last.

fmulInt :: BFOpts -> BF -> Int64 -> BF -> IO Status Source #

Multiply the number by the given int, and store the result in the second number.

fmulWord :: BFOpts -> BF -> Word64 -> BF -> IO Status Source #

Multiply the number by the given word, and store the result in the second number.

fmul2Exp :: BFOpts -> Int -> BF -> IO Status Source #

Multiply the number by `2^e`.

ffma :: BFOpts -> BF -> BF -> BF -> BF -> IO Status Source #

Compute the fused-multiply-add. `ffma opts x y z r` computes `r := (x*y)+z`.

fdiv :: BFOpts -> BF -> BF -> BF -> IO Status Source #

Divide two numbers, using the given settings, and store the result in the last.

frem :: BFOpts -> BF -> BF -> BF -> IO 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`). Output is written into the final argument.

fsqrt :: BFOpts -> BF -> BF -> IO Status Source #

Compute the square root of the first number and store the result in the second.

fpow :: BFOpts -> BF -> BF -> BF -> IO Status Source #

Exponentiate the first number by the second, and store the result in the third number.

fround :: BFOpts -> BF -> IO Status Source #

Round to the nearest float matching the configuration parameters.

frint :: RoundMode -> BF -> IO Status Source #

Round to the neareset integer.

# Convert from a number

toDouble :: RoundMode -> BF -> IO (Double, Status) Source #

Get the current value of a `BF` as a Haskell `Double`.

toString :: Int -> ShowFmt -> BF -> IO String Source #

Render a big-float as a Haskell string. The radix should not exceed `maxRadix`.

toRep :: BF -> IO BFRep Source #

Get the representation of the number.

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 #

# Configuration

module LibBF.Opts

toChunks :: Integer -> [LimbT] Source #

Chunk a non-negative integer into words, least significatn first