{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, UnboxedTuples #-}
{-# OPTIONS_HADDOCK not-home #-}
module GHC.Internal.Num
( Num(..)
, subtract
, quotRemInteger
, module GHC.Internal.Bignum.Integer
, module GHC.Internal.Bignum.Natural
, module GHC.Internal.Natural
, module GHC.Internal.Integer
)
where
#include "MachDeps.h"
import qualified GHC.Internal.Natural
import qualified GHC.Internal.Integer
import GHC.Internal.Base
import GHC.Internal.Bignum.Integer
import GHC.Internal.Bignum.Natural
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 #-}
a
x - a
y = a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a -> a
forall a. Num a => a -> a
negate a
y
negate a
x = a
0 a -> a -> a
forall a. Num a => a -> a -> a
- a
x
{-# INLINE subtract #-}
subtract :: (Num a) => a -> a -> a
subtract :: forall a. Num a => a -> a -> a
subtract a
x a
y = a
y a -> a -> a
forall a. Num a => a -> a -> a
- a
x
instance Num Int where
I# Int#
x + :: Int -> Int -> Int
+ I# Int#
y = Int# -> Int
I# (Int#
x Int# -> Int# -> Int#
+# Int#
y)
I# Int#
x - :: Int -> Int -> Int
- I# Int#
y = Int# -> Int
I# (Int#
x Int# -> Int# -> Int#
-# Int#
y)
negate :: Int -> Int
negate (I# Int#
x) = Int# -> Int
I# (Int# -> Int#
negateInt# Int#
x)
I# Int#
x * :: Int -> Int -> Int
* I# Int#
y = Int# -> Int
I# (Int#
x Int# -> Int# -> Int#
*# Int#
y)
abs :: Int -> Int
abs Int
n = if Int
n Int -> Int -> Bool
`geInt` Int
0 then Int
n else Int -> Int
forall a. Num a => a -> a
negate Int
n
signum :: Int -> Int
signum Int
n | Int
n Int -> Int -> Bool
`ltInt` Int
0 = Int -> Int
forall a. Num a => a -> a
negate Int
1
| Int
n Int -> Int -> Bool
`eqInt` Int
0 = Int
0
| Bool
otherwise = Int
1
fromInteger :: Integer -> Int
fromInteger Integer
i = Int# -> Int
I# (Integer -> Int#
integerToInt# Integer
i)
instance Num Word where
(W# Word#
x#) + :: Word -> Word -> Word
+ (W# Word#
y#) = Word# -> Word
W# (Word#
x# Word# -> Word# -> Word#
`plusWord#` Word#
y#)
(W# Word#
x#) - :: Word -> Word -> Word
- (W# Word#
y#) = Word# -> Word
W# (Word#
x# Word# -> Word# -> Word#
`minusWord#` Word#
y#)
(W# Word#
x#) * :: Word -> Word -> Word
* (W# Word#
y#) = Word# -> Word
W# (Word#
x# Word# -> Word# -> Word#
`timesWord#` Word#
y#)
negate :: Word -> Word
negate (W# Word#
x#) = Word# -> Word
W# (Int# -> Word#
int2Word# (Int# -> Int#
negateInt# (Word# -> Int#
word2Int# Word#
x#)))
abs :: Word -> Word
abs Word
x = Word
x
signum :: Word -> Word
signum Word
0 = Word
0
signum Word
_ = Word
1
fromInteger :: Integer -> Word
fromInteger Integer
i = Word# -> Word
W# (Integer -> Word#
integerToWord# Integer
i)
instance Num Integer where
+ :: Integer -> Integer -> Integer
(+) = Integer -> Integer -> Integer
integerAdd
(-) = Integer -> Integer -> Integer
integerSub
* :: Integer -> Integer -> Integer
(*) = Integer -> Integer -> Integer
integerMul
negate :: Integer -> Integer
negate = Integer -> Integer
integerNegate
fromInteger :: Integer -> Integer
fromInteger Integer
i = Integer
i
abs :: Integer -> Integer
abs = Integer -> Integer
integerAbs
signum :: Integer -> Integer
signum = Integer -> Integer
integerSignum
instance Num Natural where
+ :: Natural -> Natural -> Natural
(+) = Natural -> Natural -> Natural
naturalAdd
(-) = Natural -> Natural -> Natural
naturalSubThrow
* :: Natural -> Natural -> Natural
(*) = Natural -> Natural -> Natural
naturalMul
negate :: Natural -> Natural
negate = Natural -> Natural
naturalNegate
fromInteger :: Integer -> Natural
fromInteger Integer
i = Integer -> Natural
integerToNaturalThrow Integer
i
abs :: Natural -> Natural
abs = Natural -> Natural
forall a. a -> a
id
signum :: Natural -> Natural
signum = Natural -> Natural
naturalSignum
{-# DEPRECATED quotRemInteger "Use integerQuotRem# instead" #-}
quotRemInteger :: Integer -> Integer -> (# Integer, Integer #)
quotRemInteger :: Integer -> Integer -> (# Integer, Integer #)
quotRemInteger = Integer -> Integer -> (# Integer, Integer #)
integerQuotRem#