libBF-0.6.2: A binding to the libBF library.
Safe HaskellTrustworthy
LanguageHaskell2010

LibBF

Description

Computation with high-precision floats.

Synopsis

Constants

data BigFloat Source #

Arbitrary precision floating point numbers.

Instances

Instances details
Eq BigFloat Source #

IEEE 754 equality

Instance details

Defined in LibBF

Ord BigFloat Source #

IEEE 754 comparisons

Instance details

Defined in LibBF

Show BigFloat Source # 
Instance details

Defined in LibBF

NFData BigFloat Source # 
Instance details

Defined in LibBF

Methods

rnf :: BigFloat -> () #

Hashable BigFloat Source # 
Instance details

Defined in LibBF

Methods

hashWithSalt :: Int -> BigFloat -> Int #

hash :: BigFloat -> Int #

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.

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
Eq BFRep Source # 
Instance details

Defined in LibBF.Mutable

Methods

(==) :: BFRep -> BFRep -> Bool #

(/=) :: BFRep -> BFRep -> Bool #

Ord BFRep Source # 
Instance details

Defined in LibBF.Mutable

Methods

compare :: BFRep -> BFRep -> Ordering #

(<) :: BFRep -> BFRep -> Bool #

(<=) :: BFRep -> BFRep -> Bool #

(>) :: BFRep -> BFRep -> Bool #

(>=) :: BFRep -> BFRep -> Bool #

max :: BFRep -> BFRep -> BFRep #

min :: BFRep -> BFRep -> BFRep #

Show BFRep Source # 
Instance details

Defined in LibBF.Mutable

Methods

showsPrec :: Int -> BFRep -> ShowS #

show :: BFRep -> String #

showList :: [BFRep] -> ShowS #

Hashable BFRep Source # 
Instance details

Defined in LibBF.Mutable

Methods

hashWithSalt :: Int -> BFRep -> Int #

hash :: BFRep -> Int #

data BFNum Source #

Representations for unsigned floating point numbers.

Constructors

Zero

zero

Num Integer !Int64
x * 2 ^ y
Inf

infinity

Instances

Instances details
Eq BFNum Source # 
Instance details

Defined in LibBF.Mutable

Methods

(==) :: BFNum -> BFNum -> Bool #

(/=) :: BFNum -> BFNum -> Bool #

Ord BFNum Source # 
Instance details

Defined in LibBF.Mutable

Methods

compare :: BFNum -> BFNum -> Ordering #

(<) :: BFNum -> BFNum -> Bool #

(<=) :: BFNum -> BFNum -> Bool #

(>) :: BFNum -> BFNum -> Bool #

(>=) :: BFNum -> BFNum -> Bool #

max :: BFNum -> BFNum -> BFNum #

min :: BFNum -> BFNum -> BFNum #

Show BFNum Source # 
Instance details

Defined in LibBF.Mutable

Methods

showsPrec :: Int -> BFNum -> ShowS #

show :: BFNum -> String #

showList :: [BFNum] -> ShowS #

Hashable BFNum Source # 
Instance details

Defined in LibBF.Mutable

Methods

hashWithSalt :: Int -> BFNum -> Int #

hash :: BFNum -> Int #

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
Eq Sign Source # 
Instance details

Defined in LibBF.Mutable

Methods

(==) :: Sign -> Sign -> Bool #

(/=) :: Sign -> Sign -> Bool #

Ord Sign Source # 
Instance details

Defined in LibBF.Mutable

Methods

compare :: Sign -> Sign -> Ordering #

(<) :: Sign -> Sign -> Bool #

(<=) :: Sign -> Sign -> Bool #

(>) :: Sign -> Sign -> Bool #

(>=) :: Sign -> Sign -> Bool #

max :: Sign -> Sign -> Sign #

min :: Sign -> Sign -> Sign #

Show Sign Source # 
Instance details

Defined in LibBF.Mutable

Methods

showsPrec :: Int -> Sign -> ShowS #

show :: Sign -> String #

showList :: [Sign] -> ShowS #

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 -> Int64 -> (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