diff options
Diffstat (limited to 'libraries/base/GHC/Real.hs')
-rw-r--r-- | libraries/base/GHC/Real.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libraries/base/GHC/Real.hs b/libraries/base/GHC/Real.hs index 4329bb7355..696cb8a52e 100644 --- a/libraries/base/GHC/Real.hs +++ b/libraries/base/GHC/Real.hs @@ -817,3 +817,22 @@ integralEnumFromTo n m = map fromInteger [toInteger n .. toInteger m] integralEnumFromThenTo :: Integral a => a -> a -> a -> [a] integralEnumFromThenTo n1 n2 m = map fromInteger [toInteger n1, toInteger n2 .. toInteger m] + +-- mkRational related code + +data FractionalExponentBase + = Base2 + | Base10 + deriving (Show) + +mkRationalBase2 :: Rational -> Integer -> Rational +mkRationalBase2 r e = mkRationalWithExponentBase r e Base2 + +mkRationalBase10 :: Rational -> Integer -> Rational +mkRationalBase10 r e = mkRationalWithExponentBase r e Base10 + +mkRationalWithExponentBase :: Rational -> Integer + -> FractionalExponentBase -> Rational +mkRationalWithExponentBase r e feb = r * (eb ^^ e) + -- See Note [fractional exponent bases] for why only these bases. + where eb = case feb of Base2 -> 2 ; Base10 -> 10 |