Copyright | (c) 2018 Rudy Matela |
---|---|
License | 3-Clause BSD (see the file LICENSE) |
Maintainer | Rudy Matela <rudy@matela.com.br> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- data Quotient
- (%) :: Integer -> Integer -> Quotient
- infinity :: Quotient
- nan :: Quotient
- isInfinite :: Quotient -> Bool
- isNaN :: Quotient -> Bool
- readQ :: String -> Quotient
- maybeReadQ :: String -> Maybe Quotient
- digits :: Int -> Quotient -> Either String ([Int], [Int], [Int])
- fracDigits :: Int -> Quotient -> ([Int], [Int])
Documentation
Our own Ratio type that allows Infinity and NaN
Instances
Num Quotient Source # | |
Fractional Quotient Source # | |
Real Quotient Source # | |
Defined in Text.PercentFormat.Quotient toRational :: Quotient -> Rational # | |
RealFrac Quotient Source # | |
Show Quotient Source # | |
Eq Quotient Source # |
|
Ord Quotient Source # |
|
Defined in Text.PercentFormat.Quotient |
isInfinite :: Quotient -> Bool Source #
Returns whether a given quotient is an infinity (+/-).
digits :: Int -> Quotient -> Either String ([Int], [Int], [Int]) Source #
Given a quotient (rational number), returns a tuple with its integer part, its fractional digits and the period size (last fractional digits). The signal is ignored.
> digits 10 (1234567 / 100) Right ([1,2,3,4,5],[6,7],[]) > digits 10 (1/3) Right ([0],[3],1) > digits 10 (1/6) Right ([0],[1,6],1) > digits 10 (1/7) Right ([0],[1,4,2,8,5,7],6) > digits 10 (1/11) Right ([0],[0,9],2) digits 10 (1/12) Right ([0],[0,8,3],1) > digits 10 (1/13) Right ([0],[0,7,6,9,2,3],6) > digits 10 123 Right ([1,2,3],[],[]) > digits 10 (-4/3) Right ([1],[],[3]) > digits 10 (-1/3) Right ([0],[],[3])
fracDigits :: Int -> Quotient -> ([Int], [Int]) Source #
Givent a base, returns the fractional digits of a Quotient (including a period if present).
> fracDigits 10 (123 / 100) ([2,3],[]) > fracDigits 10 (12345 / 100) ([4,5],[]) > fracDigits 10 (12345 / 10) ([5],[]) > fracDigits 10 (100 / 10) ([],[]) > fracDigits 10 (1 / 3) ([],[3]) > fracDigits 10 (1 / 7) ([],[1,4,2,8,5,7])