libBF-0.6.6: A binding to the libBF library.

Safe Haskell | None
Language | Haskell2010

LibBF.Opts

Contents

- Options
  - Presets
  - Precision
  - Exponent Size
  - Rounding mode
  - Pretty printing options
- Status
- Internal

Description

Configuration and results for FP computation.

Synopsis

- data BFOpts = BFOpts !LimbT !FlagsT
- allowSubnormal :: BFOpts
- float16 :: RoundMode -> BFOpts
- float32 :: RoundMode -> BFOpts
- float64 :: RoundMode -> BFOpts
- float128 :: RoundMode -> BFOpts
- float256 :: RoundMode -> BFOpts
- precBits :: Word -> BFOpts
- getPrecBits :: BFOpts -> Word
- precBitsMin :: Int
- precBitsMax :: Int
- infPrec :: BFOpts
- expBits :: Int -> BFOpts
- getExpBits :: BFOpts -> Int
- expBitsMin :: Int
- expBitsMax :: Int
- rnd :: RoundMode -> BFOpts
- newtype RoundMode = RoundMode FlagsT
- pattern NearEven :: RoundMode
- pattern ToZero :: RoundMode
- pattern ToNegInf :: RoundMode
- pattern ToPosInf :: RoundMode
- pattern NearAway :: RoundMode
- pattern Away :: RoundMode
- pattern Faithful :: RoundMode
- data ShowFmt = ShowFmt !LimbT !FlagsT
- showRnd :: RoundMode -> ShowFmt
- showFixed :: Word -> ShowFmt
- showFrac :: Word -> ShowFmt
- showFree :: Maybe Word -> ShowFmt
- showFreeMin :: Maybe Word -> ShowFmt
- addPrefix :: ShowFmt
- forceExp :: ShowFmt
- radixMax :: Int
- newtype Status = Status CInt
- pattern Ok :: Status
- pattern InvalidOp :: Status
- pattern DivideByZero :: Status
- pattern Overflow :: Status
- pattern Underflow :: Status
- pattern Inexact :: Status
- pattern MemError :: Status
- type LimbT = Word64
- type SLimbT = Int64
- type FlagsT = Word32

# Options

data BFOpts Source #

Specifies various computation settings, combined with `Semigroup`.

Constructors

BFOpts !LimbT !FlagsT |

#### Instances

Instances details

Semigroup BFOpts Source # |
Instance details Defined in LibBF.Opts Methods (<>) :: BFOpts -> BFOpts -> BFOpts Source # sconcat :: NonEmpty BFOpts -> BFOpts Source # stimes :: Integral b => b -> BFOpts -> BFOpts Source #

allowSubnormal :: BFOpts Source #

Allow denormalized answers.

## Presets

float16 :: RoundMode -> BFOpts Source #

Precision 11, exponent 5

float32 :: RoundMode -> BFOpts Source #

Precision 24, exponent 8

float64 :: RoundMode -> BFOpts Source #

Precision 53, exponent 11

float128 :: RoundMode -> BFOpts Source #

Precision 113, exponent 15

float256 :: RoundMode -> BFOpts Source #

Precision 237, exponent 19

## Precision

precBits :: Word -> BFOpts Source #

Use this many bits to represent the mantissa in the computation. The input should be in the interval defined by `precMin` and `precMax`

getPrecBits :: BFOpts -> Word Source #

Retrieve how many bits to represent the mantissa in the computation.

precBitsMin :: Int Source #

The smallest supported precision (in bits).

precBitsMax :: Int Source #

The largest supported precision (in bits). Memory could run out before we run out of precision.

infPrec :: BFOpts Source #

Use infinite precision. This should be used with caution, as it could exhause memory, and at the moment the library does not handle this gracefully at all (core dumps).

## Exponent Size

expBits :: Int -> BFOpts Source #

Set how many bits to use to represent the exponent. Should fit in the range defined by `expBitsMin` and `expBitsMax`.

getExpBits :: BFOpts -> Int Source #

Get the number of exponent bits from a `BFOpts` value.

expBitsMin :: Int Source #

The smallest supported number of bits in the exponent.

expBitsMax :: Int Source #

The largest number of exponent bits supported.

## Rounding mode

rnd :: RoundMode -> BFOpts Source #

Use the given rounding mode. If none is specified, then the default is `NearEven`.

newtype RoundMode Source #

Specifies how to round when the result can't be precise.

Constructors

RoundMode FlagsT |

#### Instances

Instances details

Show RoundMode Source # |
Instance details Defined in LibBF.Opts Methods showsPrec :: Int -> RoundMode -> ShowS Source # show :: RoundMode -> String Source # showList :: [RoundMode] -> ShowS Source #

pattern NearEven :: RoundMode Source #

Round to nearest, ties go to even.

pattern ToZero :: RoundMode Source #

Round toward zero.

pattern ToNegInf :: RoundMode Source #

Round down (toward -inf).

pattern ToPosInf :: RoundMode Source #

Round up (toward +inf).

pattern NearAway :: RoundMode Source #

Round to nearest, ties go away from zero.

pattern Away :: RoundMode Source #

Round away from zero

pattern Faithful :: RoundMode Source #

Faithful rounding (nondeterministic, either `ToPosInf` or `ToNegInf`). The `Inexact` flag is always set.

## Pretty printing options

data ShowFmt Source #

Settings for rendering numbers as `String`.

Constructors

ShowFmt !LimbT !FlagsT |

#### Instances

Instances details

Semigroup ShowFmt Source # |
Instance details Defined in LibBF.Opts Methods (<>) :: ShowFmt -> ShowFmt -> ShowFmt Source # sconcat :: NonEmpty ShowFmt -> ShowFmt Source # stimes :: Integral b => b -> ShowFmt -> ShowFmt Source #

showRnd :: RoundMode -> ShowFmt Source #

Use this rounding mode.

showFixed :: Word -> ShowFmt Source #

Show this many significant digits total .

showFrac :: Word -> ShowFmt Source #

Show this many digits after the decimal point.

showFree :: Maybe Word -> ShowFmt Source #

Use as many digits as necessary to match the required precision rounding to nearest and the subnormal+exponent configuration of `FlagsT`. The result is meaningful only if the input is already rounded to the wanted precision.

Infinite precision, indicated by giving `Nothing` for the precision is supported when the radix is a power of two.

showFreeMin :: Maybe Word -> ShowFmt Source #

same as `showFree` but uses the minimum number of digits (takes more computation time).

addPrefix :: ShowFmt Source #

add 0x prefix for base 16, 0o prefix for base 8 or 0b prefix for base 2 if non zero value

forceExp :: ShowFmt Source #

Show in exponential form.

radixMax :: Int Source #

Maximum radix when rendering to a for `bf_atof` and `bf_froa`.

# Status

newtype Status Source #

A set of flags indicating things that might go wrong.

Constructors

Status CInt |

#### Instances

Instances details

Monoid Status Source # |
Instance details Defined in LibBF.Opts Methods mempty :: Status Source # mappend :: Status -> Status -> Status Source # mconcat :: [Status] -> Status Source #
Semigroup Status Source # |
Instance details Defined in LibBF.Opts Methods (<>) :: Status -> Status -> Status Source # sconcat :: NonEmpty Status -> Status Source # stimes :: Integral b => b -> Status -> Status Source #
Show Status Source # |
Instance details Defined in LibBF.Opts Methods showsPrec :: Int -> Status -> ShowS Source # show :: Status -> String Source # showList :: [Status] -> ShowS Source #
Eq Status Source # |
Instance details Defined in LibBF.Opts Methods (==) :: Status -> Status -> Bool Source # (/=) :: Status -> Status -> Bool Source #
Ord Status Source # |
Instance details Defined in LibBF.Opts Methods compare :: Status -> Status -> Ordering Source # (<) :: Status -> Status -> Bool Source # (<=) :: Status -> Status -> Bool Source # (>) :: Status -> Status -> Bool Source # (>=) :: Status -> Status -> Bool Source # max :: Status -> Status -> Status Source # min :: Status -> Status -> Status Source #

pattern Ok :: Status Source #

Succeeds if everything is OK.

pattern InvalidOp :: Status Source #

We tried to perform an invalid operation.

pattern DivideByZero :: Status Source #

We divided by zero.

pattern Overflow :: Status Source #

The result can't be represented because it is too large.

pattern Underflow :: Status Source #

The result can't be represented because it is too small.

pattern Inexact :: Status Source #

The result is not exact.

pattern MemError :: Status Source #

Memory error. `NaN` is returned.

# Internal

type LimbT = Word64 Source #

Internal: type for limbs

type SLimbT = Int64 Source #

Internal: type for signed limbs

type FlagsT = Word32 Source #

Internal: type for flags