{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}
{-# OPTIONS_HADDOCK hide #-}
module GHC.Num (module GHC.Num, module GHC.Integer) where
import GHC.Base
import GHC.Integer
infixl 7 *
infixl 6 +, -
default ()
class Num a where
{-# MINIMAL (+), (*), abs, signum, fromInteger, (negate | (-)) #-}
(+), (-), (*) :: a -> a -> a
negate :: a -> a
abs :: a -> a
signum :: a -> a
fromInteger :: Integer -> a
{-# INLINE (-) #-}
{-# INLINE negate #-}
x - y = x + negate y
negate x = 0 - x
{-# INLINE subtract #-}
subtract :: (Num a) => a -> a -> a
subtract x y = y - x
instance Num Int where
I# x + I# y = I# (x +# y)
I# x - I# y = I# (x -# y)
negate (I# x) = I# (negateInt# x)
I# x * I# y = I# (x *# y)
abs n = if n `geInt` 0 then n else negate n
signum n | n `ltInt` 0 = negate 1
| n `eqInt` 0 = 0
| otherwise = 1
{-# INLINE fromInteger #-}
fromInteger i = I# (integerToInt i)
instance Num Word where
(W# x#) + (W# y#) = W# (x# `plusWord#` y#)
(W# x#) - (W# y#) = W# (x# `minusWord#` y#)
(W# x#) * (W# y#) = W# (x# `timesWord#` y#)
negate (W# x#) = W# (int2Word# (negateInt# (word2Int# x#)))
abs x = x
signum 0 = 0
signum _ = 1
fromInteger i = W# (integerToWord i)
instance Num Integer where
(+) = plusInteger
(-) = minusInteger
(*) = timesInteger
negate = negateInteger
fromInteger x = x
abs = absInteger
signum = signumInteger