Module
BaseRationals
- Package
- purescript-base-rationals
- Repository
- herrzinter/purescript-base-rationals
Implements in arbitrary basis given arbitrary digits:
- parsing a string for a rational
- rendering a non-fractional string represenation of a rational
Digits can be created from an Array
of Char
s.
let digits = digitsFromArray ['0', '1', '2', 'A', 'B']
toString
and fromString
run both in the (Either String)
monad,
providing String
error messages.
Both have Digits
and a basis as Int
as their first two arguments;
and a String
or a PreciseRational
as third one respectively. A usage
example is:
string :: Either String String
string = do
let pr = PR.fromInts 1 7 :: PreciseRational
let basis = 4
s <-
pure s
pr :: Either String PreciseRational
pr = do
let s = "A2AB01.20B1A" :: String
let basis = 5
pr <- fromString digits basis s
#arrayFromDigits Source
arrayFromDigits :: Digits -> Array Char
Unwrap Array
of Char
s from Digits
container
#maximalBasisOfDigits Source
maximalBasisOfDigits :: Digits -> Int
Get the maximal possible basis for Digits
. It equals the length of the
wrapped Array
of Char
s
#fromString Source
fromString :: Digits -> Int -> String -> Either String PreciseRational
Parse a PreciseRational
from a String
in basis Int
given
Digits
.
- Modules
- BaseRationals
- PreciseFloat
- PreciseRational