Module

# PreciseFloat

Package
purescript-base-rationals
Repository
herrzinter/purescript-base-rationals

### #PreciseFloatSource

``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

• `Show PreciseFloat`
• `Eq PreciseFloat`

### #fromRatioSource

``fromRatio :: PreciseRational -> PreciseFloat``

Convert a `PreciseRational` to a `PreciseFloat`, ie. convert a fractional representation of a rational to a non-fractoinal one.

### #fromIntsSource

``fromInts :: Int -> Int -> Int -> Int -> PreciseFloat``

Construct `PreciseFloat` from four `Int`s describiing `finit`, `infinit`, `infinitLength` and `shift`

### #fromStringsSource

``fromStrings :: String -> String -> String -> String -> Maybe PreciseFloat``

Try to construct `PreciseFloat` from four `Strings`s describiing `finit`, `infinit`, `infinitLength` and `shift`

### #toRatioSource

``toRatio :: PreciseFloat -> PreciseRational``

Convert a `PreciseFloat` to a `PreciseRational` ie. convert a non-fractional representation of a rational to a fractional one.

### #isRecurringSource

``isRecurring :: PreciseFloat -> Boolean``

Check if the `PreciseFloat` has a recurring part

### #isZeroSource

``isZero :: PreciseFloat -> Boolean``

Check if the `PreciseFloat` is zero

### #scaleSource

``scale :: PreciseFloat -> BigInt -> PreciseFloat``

Scale the `PreciseFloat` by a `BigInt` `factor`

### #appendNZerosOnTheRightSource

``appendNZerosOnTheRight :: BigInt -> BigInt -> BigInt``

Eg. 123 `appendNZerosOnTheRight` 2 -> 12300

### #stripNDigitsOnTheRightSource

``stripNDigitsOnTheRight :: BigInt -> BigInt -> BigInt``

eg. 12345 `stripNDigitsOnTheRight` 2 -> 123

### #toMixedRatioSource

``toMixedRatio :: PreciseRational -> { propper :: PreciseRational, whole :: BigInt }``

Seperate the `whole` from the `propper` part of an (possibly) impropper fraction