X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FReal.lhs;h=fa70ded93d66135d63c439eabdfb06237c9026a6;hb=5dac514410303675fe60985c502c2c2863da616c;hp=8b4615b2b6a5800eefaec3a57a6fdc3e3bd7ab83;hpb=aea2507724ff9ee46fe7d49dab05e532a56cf487;p=ghc-base.git diff --git a/GHC/Real.lhs b/GHC/Real.lhs index 8b4615b..fa70ded 100644 --- a/GHC/Real.lhs +++ b/GHC/Real.lhs @@ -1,5 +1,5 @@ \begin{code} -{-# OPTIONS_GHC -XNoImplicitPrelude #-} +{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, UnboxedTuples #-} {-# OPTIONS_HADDOCK hide #-} ----------------------------------------------------------------------------- -- | @@ -245,32 +245,32 @@ instance Integral Int where a `quot` b | b == 0 = divZeroError - | a == minBound && b == (-1) = overflowError + | b == (-1) && a == minBound = overflowError | otherwise = a `quotInt` b a `rem` b | b == 0 = divZeroError - | a == minBound && b == (-1) = overflowError + | b == (-1) && a == minBound = overflowError | otherwise = a `remInt` b a `div` b | b == 0 = divZeroError - | a == minBound && b == (-1) = overflowError + | b == (-1) && a == minBound = overflowError | otherwise = a `divInt` b a `mod` b | b == 0 = divZeroError - | a == minBound && b == (-1) = overflowError + | b == (-1) && a == minBound = overflowError | otherwise = a `modInt` b a `quotRem` b | b == 0 = divZeroError - | a == minBound && b == (-1) = overflowError + | b == (-1) && a == minBound = overflowError | otherwise = a `quotRemInt` b a `divMod` b | b == 0 = divZeroError - | a == minBound && b == (-1) = overflowError + | b == (-1) && a == minBound = overflowError | otherwise = a `divModInt` b \end{code} @@ -328,6 +328,7 @@ instance (Integral a) => Num (Ratio a) where signum (x:%_) = signum x :% 1 fromInteger x = fromInteger x :% 1 +{-# RULES "fromRational/id" fromRational = id :: Rational -> Rational #-} instance (Integral a) => Fractional (Ratio a) where {-# SPECIALIZE instance Fractional Rational #-} (x:%y) / (x':%y') = (x*y') % (y*x') @@ -335,7 +336,7 @@ instance (Integral a) => Fractional (Ratio a) where recip (x:%y) | x < 0 = negate y :% negate x | otherwise = y :% x - fromRational (x:%y) = fromInteger x :% fromInteger y + fromRational (x:%y) = fromInteger x % fromInteger y instance (Integral a) => Real (Ratio a) where {-# SPECIALIZE instance Real Rational #-} @@ -423,6 +424,7 @@ odd = not . even Integer -> Integer -> Integer, Integer -> Int -> Integer, Int -> Int -> Int #-} +{-# INLINABLE (^) #-} -- See Note [Inlining (^)] (^) :: (Num a, Integral b) => a -> b -> a x0 ^ y0 | y0 < 0 = error "Negative exponent" | y0 == 0 = 1 @@ -438,8 +440,20 @@ x0 ^ y0 | y0 < 0 = error "Negative exponent" -- | raise a number to an integral power (^^) :: (Fractional a, Integral b) => a -> b -> a +{-# INLINABLE (^^) #-} -- See Note [Inlining (^) x ^^ n = if n >= 0 then x^n else recip (x^(negate n)) +{- Note [Inlining (^) + ~~~~~~~~~~~~~~~~~~~~~ + The INLINABLE pragma allows (^) to be specialised at its call sites. + If it is called repeatedly at the same type, that can make a huge + difference, because of those constants which can be repeatedly + calculated. + + Currently the fromInteger calls are not floated because we get + \d1 d2 x y -> blah + after the gentle round of simplification. -} + ------------------------------------------------------- -- Special power functions for Rational --