PreciseFloat
- Package
- purescript-base-rationals
- Repository
- herrzinter/purescript-base-rationals
#PreciseFloat Source
data PreciseFloatThe PreciseFloat data type is a non-fractional representation of
rational numbers, ie. it is an infinit precision floating point number.
Rational numbers can have recurring, and thus, infinit, non-fractional
represenations. The finit, ie. not recurring, and infinit , ie.
recurring, part are seperated.
infinitLength specifies the length of the infinit part. This is
necessarry to encode the difference between infinit parts which are lead by
zeros and infinit parts which are not, eg.
"0.[1]" and "0.[001]" have both infinit = 1, but different
infinitLengths.
shift specifies by how many digits the radix points has to be shifted to
the left, so that, finit and infinit become whole numbers. Thus,
in contrast to traditional floating point types, shift is only positive,
and always interpreted as negative exponent, eg.
"1000" is coded as {f: 1000, i: 0, il: 0, s: 0},
but "0.001" as {f: 1, i: 0, il: 0, s: 3}
Constructors
PreciseFloat { finit :: BigInt, infinit :: BigInt, infinitLength :: BigInt, shift :: BigInt }
Instances
#fromRatio Source
fromRatio :: PreciseRational -> PreciseFloatConvert a PreciseRational to a PreciseFloat, ie. convert a fractional
representation of a rational to a non-fractoinal one.
#fromStrings Source
fromStrings :: String -> String -> String -> String -> Maybe PreciseFloatTry to construct PreciseFloat from four Stringss describiing finit,
infinit, infinitLength and shift
#toRatio Source
toRatio :: PreciseFloat -> PreciseRationalConvert a PreciseFloat to a PreciseRational ie. convert a
non-fractional representation of a rational to a fractional one.
#isRecurring Source
isRecurring :: PreciseFloat -> BooleanCheck if the PreciseFloat has a recurring part
#isZero Source
isZero :: PreciseFloat -> BooleanCheck if the PreciseFloat is zero
#scale Source
scale :: PreciseFloat -> BigInt -> PreciseFloatScale the PreciseFloat by a BigInt factor
#appendNZerosOnTheRight Source
appendNZerosOnTheRight :: BigInt -> BigInt -> BigIntEg. 123 appendNZerosOnTheRight 2 -> 12300
#stripNDigitsOnTheRight Source
stripNDigitsOnTheRight :: BigInt -> BigInt -> BigInteg. 12345 stripNDigitsOnTheRight 2 -> 123
#toMixedRatio Source
toMixedRatio :: PreciseRational -> { propper :: PreciseRational, whole :: BigInt }Seperate the whole from the propper part of an (possibly) impropper
fraction
- Modules
- BaseRationals
- PreciseFloat
- PreciseRational