Export Unicode and newline functionality from System.IO; update Haddock docs
[ghc-base.git] / GHC / Real.lhs
index 197bcde..6a3f335 100644 (file)
@@ -24,6 +24,7 @@ import GHC.Num
 import GHC.List
 import GHC.Enum
 import GHC.Show
+import GHC.Err
 
 infixr 8  ^, ^^
 infixl 7  /, `quot`, `rem`, `div`, `mod`
@@ -173,7 +174,8 @@ class  (Real a, Fractional a) => RealFrac a  where
     properFraction      :: (Integral b) => a -> (b,a)
     -- | @'truncate' x@ returns the integer nearest @x@ between zero and @x@
     truncate            :: (Integral b) => a -> b
-    -- | @'round' x@ returns the nearest integer to @x@
+    -- | @'round' x@ returns the nearest integer to @x@;
+    --   the even integer if @x@ is equidistant between two integers
     round               :: (Integral b) => a -> b
     -- | @'ceiling' x@ returns the least integer not less than @x@
     ceiling             :: (Integral b) => a -> b
@@ -337,8 +339,11 @@ instance  (Integral a)  => Show (Ratio a)  where
     {-# SPECIALIZE instance Show Rational #-}
     showsPrec p (x:%y)  =  showParen (p > ratioPrec) $
                            showsPrec ratioPrec1 x . 
-                           showString "%" .     -- H98 report has spaces round the %
-                                                -- but we removed them [May 04]
+                           showString " % " .
+                           -- H98 report has spaces round the %
+                           -- but we removed them [May 04]
+                           -- and added them again for consistency with
+                           -- Haskell 98 [Sep 08, #1920]
                            showsPrec ratioPrec1 y
 
 instance  (Integral a)  => Enum (Ratio a)  where
@@ -446,16 +451,20 @@ lcm x y         =  abs ((x `quot` (gcd x y)) * y)
 
 {-# RULES
 "gcd/Int->Int->Int"             gcd = gcdInt
+"gcd/Integer->Integer->Integer" gcd = gcdInteger'
+"lcm/Integer->Integer->Integer" lcm = lcmInteger
  #-}
 
--- XXX these optimisation rules are disabled for now to make it easier
---     to experiment with other Integer implementations
--- "gcd/Integer->Integer->Integer" gcd = gcdInteger'
--- "lcm/Integer->Integer->Integer" lcm = lcmInteger
+-- XXX to use another Integer implementation, you might need to disable
+-- the gcd/Integer and lcm/Integer RULES above
 --
--- gcdInteger' :: Integer -> Integer -> Integer
--- gcdInteger' 0 0 = error "GHC.Real.gcdInteger': gcd 0 0 is undefined"
--- gcdInteger' a b = gcdInteger a b
+gcdInteger' :: Integer -> Integer -> Integer
+gcdInteger' 0 0 = error "GHC.Real.gcdInteger': gcd 0 0 is undefined"
+gcdInteger' a b = gcdInteger a b
+
+gcdInt :: Int -> Int -> Int
+gcdInt 0 0 = error "GHC.Real.gcdInt: gcd 0 0 is undefined"
+gcdInt a b = fromIntegral (gcdInteger (fromIntegral a) (fromIntegral b))
 
 integralEnumFrom :: (Integral a, Bounded a) => a -> [a]
 integralEnumFrom n = map fromInteger [toInteger n .. toInteger (maxBound `asTypeOf` n)]