X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FNum.lhs;h=5dc5e753d1e99633df774f2ec95789e64d37d2c8;hb=be2750a0a11b919fb03cc070074e430f88bdfa90;hp=da4ab04a6ad9b3f597dd684474eee1700584d3ff;hpb=5c99290b8ab03f819f7b630f374187a254b0cea1;p=ghc-base.git diff --git a/GHC/Num.lhs b/GHC/Num.lhs index da4ab04..5dc5e75 100644 --- a/GHC/Num.lhs +++ b/GHC/Num.lhs @@ -1,5 +1,7 @@ \begin{code} -{-# OPTIONS_GHC -XNoImplicitPrelude #-} +{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, UnboxedTuples #-} +-- We believe we could deorphan this module, by moving lots of things +-- around, but we haven't got there yet: {-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_HADDOCK hide #-} ----------------------------------------------------------------------------- @@ -7,7 +9,7 @@ -- Module : GHC.Num -- 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) @@ -41,7 +43,7 @@ import GHC.Integer infixl 7 * infixl 6 +, - -default () -- Double isn't available yet, +default () -- Double isn't available yet, -- and we shouldn't be using defaults anyway \end{code} @@ -62,7 +64,7 @@ class (Eq a, Show a) => Num a where -- | Absolute value. abs :: a -> a -- | Sign of a number. - -- The functions 'abs' and 'signum' should satisfy the law: + -- The functions 'abs' and 'signum' should satisfy the law: -- -- > abs x * signum x == x -- @@ -75,6 +77,8 @@ class (Eq a, Show a) => Num a where -- so such literals have type @('Num' a) => a@. fromInteger :: Integer -> a + {-# INLINE (-) #-} + {-# INLINE negate #-} x - y = x + negate y negate x = 0 - x @@ -107,6 +111,7 @@ instance Num Int where | n `eqInt` 0 = 0 | otherwise = 1 + {-# INLINE fromInteger #-} -- Just to be sure! fromInteger i = I# (toInt# i) quotRemInt :: Int -> Int -> (Int, Int) @@ -120,27 +125,6 @@ divModInt x@(I# _) y@(I# _) = (x `divInt` y, x `modInt` y) %********************************************************* %* * -\subsection{The @Integer@ instances for @Eq@, @Ord@} -%* * -%********************************************************* - -\begin{code} -instance Eq Integer where - (==) = eqInteger - (/=) = neqInteger - ------------------------------------------------------------------------- -instance Ord Integer where - (<=) = leInteger - (>) = gtInteger - (<) = ltInteger - (>=) = geInteger - compare = compareInteger -\end{code} - - -%********************************************************* -%* * \subsection{The @Integer@ instances for @Show@} %* * %********************************************************* @@ -180,8 +164,8 @@ integerToString n0 cs0 jsplith p (n:ns) = case n `quotRemInteger` p of (# q, r #) -> - if q > 0 then fromInteger q : fromInteger r : jsplitb p ns - else fromInteger r : jsplitb p ns + if q > 0 then q : r : jsplitb p ns + else r : jsplitb p ns jsplith _ [] = error "jsplith: []" jsplitb :: Integer -> [Integer] -> [Integer] @@ -293,6 +277,8 @@ enumDeltaInteger x d = x `seq` (x : enumDeltaInteger (x+d) d) -- head (drop 1000000 [1 .. ] -- works +{-# NOINLINE [0] enumDeltaToIntegerFB #-} +-- Don't inline this until RULE "enumDeltaToInteger" has had a chance to fire enumDeltaToIntegerFB :: (Integer -> a -> a) -> a -> Integer -> Integer -> Integer -> a enumDeltaToIntegerFB c n x delta lim