-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | A binding to the libBF library.
--   
--   LibBF is a C library for working with arbitray precision IEEE 754
--   floating point numbers.
@package libBF
@version 0.6.8

-- | Configuration and results for FP computation.
module LibBF.Opts

-- | Specifies various computation settings, combined with
--   Semigroup.
data BFOpts
BFOpts :: !LimbT -> !FlagsT -> BFOpts

-- | Allow denormalized answers.
allowSubnormal :: BFOpts

-- | Precision 11, exponent 5
float16 :: RoundMode -> BFOpts

-- | Precision 24, exponent 8
float32 :: RoundMode -> BFOpts

-- | Precision 53, exponent 11
float64 :: RoundMode -> BFOpts

-- | Precision 113, exponent 15
float128 :: RoundMode -> BFOpts

-- | Precision 237, exponent 19
float256 :: RoundMode -> BFOpts

-- | Use this many bits to represent the mantissa in the computation. The
--   input should be in the interval defined by precMin and
--   precMax
precBits :: Word -> BFOpts

-- | Retrieve how many bits to represent the mantissa in the computation.
getPrecBits :: BFOpts -> Word

-- | The smallest supported precision (in bits).
precBitsMin :: Int

-- | The largest supported precision (in bits). Memory could run out before
--   we run out of precision.
precBitsMax :: Int

-- | 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).
infPrec :: BFOpts

-- | Set how many bits to use to represent the exponent. Should fit in the
--   range defined by expBitsMin and expBitsMax.
expBits :: Int -> BFOpts

-- | Get the number of exponent bits from a BFOpts value.
getExpBits :: BFOpts -> Int

-- | The smallest supported number of bits in the exponent.
expBitsMin :: Int

-- | The largest number of exponent bits supported.
expBitsMax :: Int

-- | Use the given rounding mode. If none is specified, then the default is
--   NearEven.
rnd :: RoundMode -> BFOpts

-- | Specifies how to round when the result can't be precise.
newtype RoundMode
RoundMode :: FlagsT -> RoundMode

-- | Round to nearest, ties go to even.
pattern NearEven :: RoundMode

-- | Round toward zero.
pattern ToZero :: RoundMode

-- | Round down (toward -inf).
pattern ToNegInf :: RoundMode

-- | Round up (toward +inf).
pattern ToPosInf :: RoundMode

-- | Round to nearest, ties go away from zero.
pattern NearAway :: RoundMode

-- | Round away from zero
pattern Away :: RoundMode

-- | Faithful rounding (nondeterministic, either ToPosInf or
--   ToNegInf). The Inexact flag is always set.
pattern Faithful :: RoundMode

-- | Settings for rendering numbers as String.
data ShowFmt
ShowFmt :: !LimbT -> !FlagsT -> ShowFmt

-- | Use this rounding mode.
showRnd :: RoundMode -> ShowFmt

-- | Show this many significant digits total .
showFixed :: Word -> ShowFmt

-- | Show this many digits after the decimal point.
showFrac :: Word -> ShowFmt

-- | 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.
showFree :: Maybe Word -> ShowFmt

-- | same as showFree but uses the minimum number of digits (takes
--   more computation time).
showFreeMin :: Maybe Word -> ShowFmt

-- | add 0x prefix for base 16, 0o prefix for base 8 or 0b prefix for base
--   2 if non zero value
addPrefix :: ShowFmt

-- | Show in exponential form.
forceExp :: ShowFmt

-- | Maximum radix when rendering to a for bf_atof and
--   bf_froa.
radixMax :: Int

-- | A set of flags indicating things that might go wrong.
newtype Status
Status :: CInt -> Status

-- | Succeeds if everything is OK.
pattern Ok :: Status

-- | We tried to perform an invalid operation.
pattern InvalidOp :: Status

-- | We divided by zero.
pattern DivideByZero :: Status

-- | The result can't be represented because it is too large.
pattern Overflow :: Status

-- | The result can't be represented because it is too small.
pattern Underflow :: Status

-- | The result is not exact.
pattern Inexact :: Status

-- | Memory error. NaN is returned.
pattern MemError :: Status

-- | Internal: type for limbs
type LimbT = Word64

-- | Internal: type for signed limbs
type SLimbT = Int64

-- | Internal: type for flags
type FlagsT = Word32
instance GHC.Show.Show LibBF.Opts.RoundMode
instance GHC.Classes.Ord LibBF.Opts.Status
instance GHC.Classes.Eq LibBF.Opts.Status
instance GHC.Base.Semigroup LibBF.Opts.Status
instance GHC.Base.Monoid LibBF.Opts.Status
instance GHC.Show.Show LibBF.Opts.Status
instance GHC.Base.Semigroup LibBF.Opts.ShowFmt
instance GHC.Base.Semigroup LibBF.Opts.BFOpts

-- | Mutable big-float computation.
module LibBF.Mutable

-- | Allocate a new numeric context.
newContext :: IO BFContext

-- | State of the current computation context.
data BFContext

-- | Allocate a new number. Starts off as zero.
new :: BFContext -> IO BF

-- | A mutable high precision floating point number.
data BF

-- | Assign NaN to the number.
setNaN :: BF -> IO ()

-- | Assign a zero to the number.
setZero :: Sign -> BF -> IO ()

-- | Assign an infinty to the number.
setInf :: Sign -> BF -> IO ()

-- | Indicates if a number is positive or negative.
data Sign

-- | Negative
Neg :: Sign

-- | Positive
Pos :: Sign

-- | Assign from a word
setWord :: Word64 -> BF -> IO ()

-- | Assign from an int
setInt :: Int64 -> BF -> IO ()

-- | Assign from a double
setDouble :: Double -> BF -> IO ()

-- | Set an integer. If the integer is larger than the primitive types,
--   this does repreated Int64 additions and multiplications.
setInteger :: Integer -> BF -> IO ()

-- | Assign from another number.
setBF :: BF -> BF -> IO ()

-- | 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
setString :: Int -> BFOpts -> String -> BF -> IO (Status, Int, Bool)

-- | Check if the two numbers are equal.
cmpEq :: BF -> BF -> IO Bool

-- | Check if the first number is strictly less than the second.
cmpLT :: BF -> BF -> IO Bool

-- | Check if the first number is less than, or equal to, the second.
cmpLEQ :: BF -> BF -> IO Bool

-- | Compare the absolute values of the two numbers. See also cmp.
cmpAbs :: BF -> BF -> IO Ordering

-- | Compare the two numbers. The special values are ordered like this:
--   
--   
--   
- -0 < 0
--   
- NaN == NaN
--   
- NaN is larger than all other numbers
--   
cmp :: BF -> BF -> IO Ordering

-- | Returns Nothing for NaN.
getSign :: BF -> IO (Maybe Sign)

-- | Get the exponent of the number. Returns Nothing for inifinity,
--   zero and NaN.
getExp :: BF -> IO (Maybe Int64)

-- | Check if the number is "normal", i.e. (not infinite or NaN)
isFinite :: BF -> IO Bool

-- | Check if the given numer is infinite.
isInf :: BF -> IO Bool

-- | Check if the number is NaN
isNaN :: BF -> IO Bool

-- | Check if the given number is a zero.
isZero :: BF -> IO Bool

-- | Negate the number.
fneg :: BF -> IO ()

-- | Add two numbers, using the given settings, and store the result in the
--   last.
fadd :: BFOpts -> BF -> BF -> BF -> IO Status

-- | Add a number and an int64 and store the result in the last.
faddInt :: BFOpts -> BF -> Int64 -> BF -> IO Status

-- | Subtract two numbers, using the given settings, and store the result
--   in the last.
fsub :: BFOpts -> BF -> BF -> BF -> IO Status

-- | Multiply two numbers, using the given settings, and store the result
--   in the last.
fmul :: BFOpts -> BF -> BF -> BF -> IO Status

-- | Multiply the number by the given int, and store the result in the
--   second number.
fmulInt :: BFOpts -> BF -> Int64 -> BF -> IO Status

-- | Multiply the number by the given word, and store the result in the
--   second number.
fmulWord :: BFOpts -> BF -> Word64 -> BF -> IO Status

-- | Multiply the number by 2^e.
fmul2Exp :: BFOpts -> Int -> BF -> IO Status

-- | Compute the fused-multiply-add. ffma opts x y z r computes
--   r := (x*y)+z.
ffma :: BFOpts -> BF -> BF -> BF -> BF -> IO Status

-- | Divide two numbers, using the given settings, and store the result in
--   the last.
fdiv :: BFOpts -> BF -> BF -> BF -> IO Status

-- | 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.
frem :: BFOpts -> BF -> BF -> BF -> IO Status

-- | Compute the square root of the first number and store the result in
--   the second.
fsqrt :: BFOpts -> BF -> BF -> IO Status

-- | Exponentiate the first number by the second, and store the result in
--   the third number.
fpow :: BFOpts -> BF -> BF -> BF -> IO Status

-- | Round to the nearest float matching the configuration parameters.
fround :: BFOpts -> BF -> IO Status

-- | Round to the neareset integer.
frint :: RoundMode -> BF -> IO Status

-- | Get the current value of a BF as a Haskell Double.
toDouble :: RoundMode -> BF -> IO (Double, Status)

-- | Render a big-float as a Haskell string. The radix should not exceed
--   maxRadix.
toString :: Int -> ShowFmt -> BF -> IO String

-- | Get the representation of the number.
toRep :: BF -> IO BFRep

-- | An explicit representation for big nums.
data BFRep

-- | A signed number
BFRep :: !Sign -> !BFNum -> BFRep

-- | Not a number
BFNaN :: BFRep

-- | Representations for unsigned floating point numbers.
data BFNum

-- | zero
Zero :: BFNum

-- | 
--   x * 2 ^ y
--   
Num :: Integer -> !Int64 -> BFNum

-- | infinity
Inf :: BFNum

-- | Chunk a non-negative integer into words, least significatn first
toChunks :: Integer -> [LimbT]
instance GHC.Show.Show LibBF.Mutable.Sign
instance GHC.Classes.Ord LibBF.Mutable.Sign
instance GHC.Classes.Eq LibBF.Mutable.Sign
instance Data.Data.Data LibBF.Mutable.Sign
instance GHC.Show.Show LibBF.Mutable.BFNum
instance GHC.Classes.Ord LibBF.Mutable.BFNum
instance GHC.Classes.Eq LibBF.Mutable.BFNum
instance Data.Data.Data LibBF.Mutable.BFNum
instance GHC.Show.Show LibBF.Mutable.BFRep
instance GHC.Classes.Ord LibBF.Mutable.BFRep
instance GHC.Classes.Eq LibBF.Mutable.BFRep
instance Data.Data.Data LibBF.Mutable.BFRep
instance Data.Hashable.Class.Hashable LibBF.Mutable.BFRep
instance Data.Hashable.Class.Hashable LibBF.Mutable.BFNum

-- | Computation with high-precision floats.
module LibBF

-- | Arbitrary precision floating point numbers.
data BigFloat

-- | Positive zero.
bfPosZero :: BigFloat

-- | Negative zero.
bfNegZero :: BigFloat

-- | Positive infinity.
bfPosInf :: BigFloat

-- | Negative infinity.
bfNegInf :: BigFloat

-- | Not-a-number.
bfNaN :: BigFloat

-- | A floating point number corresponding to the given word.
bfFromWord :: Word64 -> BigFloat

-- | A floating point number corresponding to the given int.
bfFromInt :: Int64 -> BigFloat

-- | A floating point number corresponding to the given double.
bfFromDouble :: Double -> BigFloat

-- | A floating point number corresponding to the given integer.
bfFromInteger :: Integer -> BigFloat

-- | Parse a number from the given string. Returns @NaN` if the string does
--   not correspond to a number we recognize.
bfFromString :: Int -> BFOpts -> String -> (BigFloat, Status)

-- | Constant to a Double
bfToDouble :: RoundMode -> BigFloat -> (Double, Status)

-- | Render as a String, using the given settings.
bfToString :: Int -> ShowFmt -> BigFloat -> String

-- | The float as an exponentiated Integer.
bfToRep :: BigFloat -> BFRep

-- | An explicit representation for big nums.
data BFRep

-- | A signed number
BFRep :: !Sign -> !BFNum -> BFRep

-- | Not a number
BFNaN :: BFRep

-- | Representations for unsigned floating point numbers.
data BFNum

-- | zero
Zero :: BFNum

-- | 
--   x * 2 ^ y
--   
Num :: Integer -> !Int64 -> BFNum

-- | infinity
Inf :: BFNum

-- | 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.
bfFromBits :: BFOpts -> Integer -> BigFloat

-- | 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).
bfToBits :: BFOpts -> BigFloat -> Integer

-- | Is this a finite (i.e., non-infinite, non NaN) number.
bfIsFinite :: BigFloat -> Bool

-- | Is this value infinite
bfIsInf :: BigFloat -> Bool

-- | Is this value a zero.
bfIsZero :: BigFloat -> Bool

-- | Is this value NaN.
bfIsNaN :: BigFloat -> Bool

-- | This is a "normal" number, which means it is not a NaN, not a zero,
--   not infinite, and not subnormal.
bfIsNormal :: BFOpts -> BigFloat -> Bool

-- | 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.
bfIsSubnormal :: BFOpts -> BigFloat -> Bool

-- | 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 (<=)
bfCompare :: BigFloat -> BigFloat -> Ordering

-- | Get the sign of a number. Returns Nothing if the number is
--   NaN.
bfSign :: BigFloat -> Maybe Sign

-- | Get the exponent for the given number. Infinity, zero and NaN do not
--   have an exponent.
bfExponent :: BigFloat -> Maybe Int64

-- | Is this value positive
bfIsPos :: BigFloat -> Bool

-- | Is this value negative
bfIsNeg :: BigFloat -> Bool

-- | Indicates if a number is positive or negative.
data Sign

-- | Negative
Neg :: Sign

-- | Positive
Pos :: Sign

-- | Negate a floating point number.
bfNeg :: BigFloat -> BigFloat

-- | Compute the absolute value of a number.
bfAbs :: BigFloat -> BigFloat

-- | Add two numbers useing the given options.
bfAdd :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)

-- | Subtract two numbers useing the given options.
bfSub :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)

-- | Multiply two numbers using the given options.
bfMul :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)

-- | Divide two numbers useing the given options.
bfDiv :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)

-- | Compute the remainder x - y * n where n is the
--   integer nearest to x/y (with ties broken to even values of
--   n).
bfRem :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)

-- | Compute the fused-multiply-add (x*y)+z
bfFMA :: BFOpts -> BigFloat -> BigFloat -> BigFloat -> (BigFloat, Status)

-- | Multiply a number and a word, using the given options.
bfMulWord :: BFOpts -> BigFloat -> Word64 -> (BigFloat, Status)

-- | Multiply a number and an int, using the given options.
bfMulInt :: BFOpts -> BigFloat -> Int64 -> (BigFloat, Status)

-- | Multiply a number by 2^e.
bfMul2Exp :: BFOpts -> BigFloat -> Int -> (BigFloat, Status)

-- | Square root of two numbers useing the given options.
bfSqrt :: BFOpts -> BigFloat -> (BigFloat, Status)

-- | Exponentiate a word to a positive integer power.
bfPow :: BFOpts -> BigFloat -> BigFloat -> (BigFloat, Status)

-- | Round to a float matching the input parameters.
bfRoundFloat :: BFOpts -> BigFloat -> (BigFloat, Status)

-- | Round to an integer using the given rounding mode.
bfRoundInt :: RoundMode -> BigFloat -> (BigFloat, Status)

-- | Make a number mutable. WARNING: This does not copy the number, so it
--   could break referential transperancy.
bfUnsafeThaw :: BigFloat -> BF

-- | Make a number immutable. WARNING: This does not copy the number, so it
--   could break referential transperancy.
bfUnsafeFreeze :: BF -> BigFloat
instance Data.Data.Data LibBF.BigFloat
instance Control.DeepSeq.NFData LibBF.BigFloat
instance GHC.Show.Show LibBF.BigFloat
instance GHC.Classes.Eq LibBF.BigFloat
instance GHC.Classes.Ord LibBF.BigFloat
instance Data.Hashable.Class.Hashable LibBF.BigFloat
