PreciseFloat
- Package
- purescript-base-rationals
- Repository
- herrzinter/purescript-base-rationals
#PreciseFloat Source
data PreciseFloat
The 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
infinitLength
s.
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 -> PreciseFloat
Convert 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 PreciseFloat
Try to construct PreciseFloat
from four Strings
s describiing finit
,
infinit
, infinitLength
and shift
#toRatio Source
toRatio :: PreciseFloat -> PreciseRational
Convert a PreciseFloat
to a PreciseRational
ie. convert a
non-fractional representation of a rational to a fractional one.
#isRecurring Source
isRecurring :: PreciseFloat -> Boolean
Check if the PreciseFloat
has a recurring part
#isZero Source
isZero :: PreciseFloat -> Boolean
Check if the PreciseFloat
is zero
#scale Source
scale :: PreciseFloat -> BigInt -> PreciseFloat
Scale the PreciseFloat
by a BigInt
factor
#appendNZerosOnTheRight Source
appendNZerosOnTheRight :: BigInt -> BigInt -> BigInt
Eg. 123 appendNZerosOnTheRight
2 -> 12300
#stripNDigitsOnTheRight Source
stripNDigitsOnTheRight :: BigInt -> BigInt -> BigInt
eg. 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