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 Chars.
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 CharUnwrap Array of Chars from Digits container
#maximalBasisOfDigits Source
maximalBasisOfDigits :: Digits -> IntGet the maximal possible basis for Digits. It equals the length of the
wrapped Array of Chars
#fromString Source
fromString :: Digits -> Int -> String -> Either String PreciseRationalParse a PreciseRational from a String in basis Int given
Digits.
- Modules
- BaseRationals
- PreciseFloat
- PreciseRational