-- Module : GHC.Real
-- Copyright : (c) The University of Glasgow, 1994-2002
-- License : see libraries/base/LICENSE
---
+--
-- Maintainer : cvs-ghc@haskell.org
-- Stability : internal
-- Portability : non-portable (GHC Extensions)
infixl 7 /, `quot`, `rem`, `div`, `mod`
infixl 7 %
-default () -- Double isn't available yet,
+default () -- Double isn't available yet,
-- and we shouldn't be using defaults anyway
\end{code}
infinity = 1 :% 0
notANumber = 0 :% 0
--- Use :%, not % for Inf/NaN; the latter would
--- immediately lead to a runtime error, because it normalises.
+-- Use :%, not % for Inf/NaN; the latter would
+-- immediately lead to a runtime error, because it normalises.
\end{code}
{-# INLINE truncate #-}
truncate x = m where (m,_) = properFraction x
-
+
round x = let (n,r) = properFraction x
m = if r < 0 then n - 1 else n + 1
in case signum (abs r - 0.5) of
0 -> if even n then n else m
1 -> m
_ -> error "round default defn: Bad value"
-
+
ceiling x = if r > 0 then n + 1 else n
where (n,r) = properFraction x
-
+
floor x = if r < 0 then n - 1 else n
where (n,r) = properFraction x
\end{code}
instance (Integral a) => Show (Ratio a) where
{-# SPECIALIZE instance Show Rational #-}
showsPrec p (x:%y) = showParen (p > ratioPrec) $
- showsPrec ratioPrec1 x .
+ showsPrec ratioPrec1 x .
showString " % " .
-- H98 report has spaces round the %
-- but we removed them [May 04]
-> Int -- ^ the precedence of the enclosing context
-> a -- ^ the value to show
-> ShowS
-showSigned showPos p x
+showSigned showPos p x
| x < 0 = showParen (p > 6) (showChar '-' . showPos (-x))
| otherwise = showPos x