{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, MagicHash, UnboxedTuples,
             StandaloneDeriving, NegativeLiterals #-}
{-# OPTIONS_HADDOCK not-home #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  GHC.Int
-- Copyright   :  (c) The University of Glasgow 1997-2002
-- License     :  see libraries/base/LICENSE
--
-- Maintainer  :  cvs-ghc@haskell.org
-- Stability   :  internal
-- Portability :  non-portable (GHC Extensions)
--
-- The sized integral datatypes, 'Int8', 'Int16', 'Int32', and 'Int64'.
--
-----------------------------------------------------------------------------

#include "MachDeps.h"

module GHC.Int (
        Int(..), Int8(..), Int16(..), Int32(..), Int64(..),
        uncheckedIShiftL64#, uncheckedIShiftRA64#,
        -- * Equality operators
        -- | See GHC.Classes#matching_overloaded_methods_in_rules
        eqInt, neInt, gtInt, geInt, ltInt, leInt,
        eqInt8, neInt8, gtInt8, geInt8, ltInt8, leInt8,
        eqInt16, neInt16, gtInt16, geInt16, ltInt16, leInt16,
        eqInt32, neInt32, gtInt32, geInt32, ltInt32, leInt32,
        eqInt64, neInt64, gtInt64, geInt64, ltInt64, leInt64
    ) where

import Data.Bits
import Data.Maybe

#if WORD_SIZE_IN_BITS < 64
import GHC.IntWord64
#endif

import GHC.Base
import GHC.Enum
import GHC.Num
import GHC.Real
import GHC.Read
import GHC.Arr
import GHC.Word hiding (uncheckedShiftL64#, uncheckedShiftRL64#)
import GHC.Show

------------------------------------------------------------------------
-- type Int8
------------------------------------------------------------------------

-- Int8 is represented in the same way as Int. Operations may assume
-- and must ensure that it holds only values from its logical range.

data {-# CTYPE "HsInt8" #-} Int8 = I8# Int#
-- ^ 8-bit signed integer type

-- See GHC.Classes#matching_overloaded_methods_in_rules
-- | @since 2.01
instance Eq Int8 where
    == :: Int8 -> Int8 -> Bool
(==) = Int8 -> Int8 -> Bool
eqInt8
    /= :: Int8 -> Int8 -> Bool
(/=) = Int8 -> Int8 -> Bool
neInt8

eqInt8, neInt8 :: Int8 -> Int8 -> Bool
eqInt8 :: Int8 -> Int8 -> Bool
eqInt8 (I8# x :: Int#
x) (I8# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
==# Int#
y)
neInt8 :: Int8 -> Int8 -> Bool
neInt8 (I8# x :: Int#
x) (I8# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
/=# Int#
y)
{-# INLINE [1] eqInt8 #-}
{-# INLINE [1] neInt8 #-}

-- | @since 2.01
instance Ord Int8 where
    < :: Int8 -> Int8 -> Bool
(<)  = Int8 -> Int8 -> Bool
ltInt8
    <= :: Int8 -> Int8 -> Bool
(<=) = Int8 -> Int8 -> Bool
leInt8
    >= :: Int8 -> Int8 -> Bool
(>=) = Int8 -> Int8 -> Bool
geInt8
    > :: Int8 -> Int8 -> Bool
(>)  = Int8 -> Int8 -> Bool
gtInt8

{-# INLINE [1] gtInt8 #-}
{-# INLINE [1] geInt8 #-}
{-# INLINE [1] ltInt8 #-}
{-# INLINE [1] leInt8 #-}
gtInt8, geInt8, ltInt8, leInt8 :: Int8 -> Int8 -> Bool
(I8# x :: Int#
x) gtInt8 :: Int8 -> Int8 -> Bool
`gtInt8` (I8# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
>#  Int#
y)
(I8# x :: Int#
x) geInt8 :: Int8 -> Int8 -> Bool
`geInt8` (I8# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
>=# Int#
y)
(I8# x :: Int#
x) ltInt8 :: Int8 -> Int8 -> Bool
`ltInt8` (I8# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
<#  Int#
y)
(I8# x :: Int#
x) leInt8 :: Int8 -> Int8 -> Bool
`leInt8` (I8# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
<=# Int#
y)

-- | @since 2.01
instance Show Int8 where
    showsPrec :: Int -> Int8 -> ShowS
showsPrec p :: Int
p x :: Int8
x = Int -> Int -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int8
x :: Int)

-- | @since 2.01
instance Num Int8 where
    (I8# x# :: Int#
x#) + :: Int8 -> Int8 -> Int8
+ (I8# y# :: Int#
y#)    = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Int#
x# Int# -> Int# -> Int#
+# Int#
y#))
    (I8# x# :: Int#
x#) - :: Int8 -> Int8 -> Int8
- (I8# y# :: Int#
y#)    = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Int#
x# Int# -> Int# -> Int#
-# Int#
y#))
    (I8# x# :: Int#
x#) * :: Int8 -> Int8 -> Int8
* (I8# y# :: Int#
y#)    = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Int#
x# Int# -> Int# -> Int#
*# Int#
y#))
    negate :: Int8 -> Int8
negate (I8# x# :: Int#
x#)        = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Int# -> Int#
negateInt# Int#
x#))
    abs :: Int8 -> Int8
abs x :: Int8
x | Int8
x Int8 -> Int8 -> Bool
forall a. Ord a => a -> a -> Bool
>= 0         = Int8
x
          | Bool
otherwise      = Int8 -> Int8
forall a. Num a => a -> a
negate Int8
x
    signum :: Int8 -> Int8
signum x :: Int8
x | Int8
x Int8 -> Int8 -> Bool
forall a. Ord a => a -> a -> Bool
> 0       = 1
    signum 0               = 0
    signum _               = -1
    fromInteger :: Integer -> Int8
fromInteger i :: Integer
i          = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Integer -> Int#
integerToInt Integer
i))

-- | @since 2.01
instance Real Int8 where
    toRational :: Int8 -> Rational
toRational x :: Int8
x = Int8 -> Integer
forall a. Integral a => a -> Integer
toInteger Int8
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% 1

-- | @since 2.01
instance Enum Int8 where
    succ :: Int8 -> Int8
succ x :: Int8
x
        | Int8
x Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Int8
forall a. Bounded a => a
maxBound = Int8
x Int8 -> Int8 -> Int8
forall a. Num a => a -> a -> a
+ 1
        | Bool
otherwise     = String -> Int8
forall a. String -> a
succError "Int8"
    pred :: Int8 -> Int8
pred x :: Int8
x
        | Int8
x Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Int8
forall a. Bounded a => a
minBound = Int8
x Int8 -> Int8 -> Int8
forall a. Num a => a -> a -> a
- 1
        | Bool
otherwise     = String -> Int8
forall a. String -> a
predError "Int8"
    toEnum :: Int -> Int8
toEnum i :: Int
i@(I# i# :: Int#
i#)
        | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int8
forall a. Bounded a => a
minBound::Int8) Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int8
forall a. Bounded a => a
maxBound::Int8)
                        = Int# -> Int8
I8# Int#
i#
        | Bool
otherwise     = String -> Int -> (Int8, Int8) -> Int8
forall a b. Show a => String -> Int -> (a, a) -> b
toEnumError "Int8" Int
i (Int8
forall a. Bounded a => a
minBound::Int8, Int8
forall a. Bounded a => a
maxBound::Int8)
    fromEnum :: Int8 -> Int
fromEnum (I8# x# :: Int#
x#)   = Int# -> Int
I# Int#
x#
    enumFrom :: Int8 -> [Int8]
enumFrom            = Int8 -> [Int8]
forall a. (Enum a, Bounded a) => a -> [a]
boundedEnumFrom
    enumFromThen :: Int8 -> Int8 -> [Int8]
enumFromThen        = Int8 -> Int8 -> [Int8]
forall a. (Enum a, Bounded a) => a -> a -> [a]
boundedEnumFromThen

-- | @since 2.01
instance Integral Int8 where
    quot :: Int8 -> Int8 -> Int8
quot    x :: Int8
x@(I8# x# :: Int#
x#) y :: Int8
y@(I8# y# :: Int#
y#)
        | Int8
y Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int8
forall a. a
divZeroError
        | Int8
y Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int8
x Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== Int8
forall a. Bounded a => a
minBound = Int8
forall a. a
overflowError -- Note [Order of tests]
        | Bool
otherwise                  = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Int#
x# Int# -> Int# -> Int#
`quotInt#` Int#
y#))
    rem :: Int8 -> Int8 -> Int8
rem     (I8# x# :: Int#
x#) y :: Int8
y@(I8# y# :: Int#
y#)
        | Int8
y Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int8
forall a. a
divZeroError
        | Bool
otherwise                  = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Int#
x# Int# -> Int# -> Int#
`remInt#` Int#
y#))
    div :: Int8 -> Int8 -> Int8
div     x :: Int8
x@(I8# x# :: Int#
x#) y :: Int8
y@(I8# y# :: Int#
y#)
        | Int8
y Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int8
forall a. a
divZeroError
        | Int8
y Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int8
x Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== Int8
forall a. Bounded a => a
minBound = Int8
forall a. a
overflowError -- Note [Order of tests]
        | Bool
otherwise                  = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Int#
x# Int# -> Int# -> Int#
`divInt#` Int#
y#))
    mod :: Int8 -> Int8 -> Int8
mod       (I8# x# :: Int#
x#) y :: Int8
y@(I8# y# :: Int#
y#)
        | Int8
y Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int8
forall a. a
divZeroError
        | Bool
otherwise                  = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Int#
x# Int# -> Int# -> Int#
`modInt#` Int#
y#))
    quotRem :: Int8 -> Int8 -> (Int8, Int8)
quotRem x :: Int8
x@(I8# x# :: Int#
x#) y :: Int8
y@(I8# y# :: Int#
y#)
        | Int8
y Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = (Int8, Int8)
forall a. a
divZeroError
          -- Note [Order of tests]
        | Int8
y Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int8
x Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== Int8
forall a. Bounded a => a
minBound = (Int8
forall a. a
overflowError, 0)
        | Bool
otherwise                  = case Int#
x# Int# -> Int# -> (# Int#, Int# #)
`quotRemInt#` Int#
y# of
                                       (# q :: Int#
q, r :: Int#
r #) ->
                                           (Int# -> Int8
I8# (Int# -> Int#
narrow8Int# Int#
q),
                                            Int# -> Int8
I8# (Int# -> Int#
narrow8Int# Int#
r))
    divMod :: Int8 -> Int8 -> (Int8, Int8)
divMod  x :: Int8
x@(I8# x# :: Int#
x#) y :: Int8
y@(I8# y# :: Int#
y#)
        | Int8
y Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = (Int8, Int8)
forall a. a
divZeroError
          -- Note [Order of tests]
        | Int8
y Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int8
x Int8 -> Int8 -> Bool
forall a. Eq a => a -> a -> Bool
== Int8
forall a. Bounded a => a
minBound = (Int8
forall a. a
overflowError, 0)
        | Bool
otherwise                  = case Int#
x# Int# -> Int# -> (# Int#, Int# #)
`divModInt#` Int#
y# of
                                       (# d :: Int#
d, m :: Int#
m #) ->
                                           (Int# -> Int8
I8# (Int# -> Int#
narrow8Int# Int#
d),
                                            Int# -> Int8
I8# (Int# -> Int#
narrow8Int# Int#
m))
    toInteger :: Int8 -> Integer
toInteger (I8# x# :: Int#
x#)               = Int# -> Integer
smallInteger Int#
x#

-- | @since 2.01
instance Bounded Int8 where
    minBound :: Int8
minBound = -0x80
    maxBound :: Int8
maxBound =  0x7F

-- | @since 2.01
instance Ix Int8 where
    range :: (Int8, Int8) -> [Int8]
range (m :: Int8
m,n :: Int8
n)         = [Int8
m..Int8
n]
    unsafeIndex :: (Int8, Int8) -> Int8 -> Int
unsafeIndex (m :: Int8
m,_) i :: Int8
i = Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int8
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int8
m
    inRange :: (Int8, Int8) -> Int8 -> Bool
inRange (m :: Int8
m,n :: Int8
n) i :: Int8
i     = Int8
m Int8 -> Int8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int8
i Bool -> Bool -> Bool
&& Int8
i Int8 -> Int8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int8
n

-- | @since 2.01
instance Read Int8 where
    readsPrec :: Int -> ReadS Int8
readsPrec p :: Int
p s :: String
s = [(Int -> Int8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
x::Int), String
r) | (x :: Int
x, r :: String
r) <- Int -> ReadS Int
forall a. Read a => Int -> ReadS a
readsPrec Int
p String
s]

-- | @since 2.01
instance Bits Int8 where
    {-# INLINE shift #-}
    {-# INLINE bit #-}
    {-# INLINE testBit #-}

    (I8# x# :: Int#
x#) .&. :: Int8 -> Int8 -> Int8
.&.   (I8# y# :: Int#
y#)   = Int# -> Int8
I8# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`and#` Int# -> Word#
int2Word# Int#
y#))
    (I8# x# :: Int#
x#) .|. :: Int8 -> Int8 -> Int8
.|.   (I8# y# :: Int#
y#)   = Int# -> Int8
I8# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`or#`  Int# -> Word#
int2Word# Int#
y#))
    (I8# x# :: Int#
x#) xor :: Int8 -> Int8 -> Int8
`xor` (I8# y# :: Int#
y#)   = Int# -> Int8
I8# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`xor#` Int# -> Word#
int2Word# Int#
y#))
    complement :: Int8 -> Int8
complement (I8# x# :: Int#
x#)       = Int# -> Int8
I8# (Word# -> Int#
word2Int# (Word# -> Word#
not# (Int# -> Word#
int2Word# Int#
x#)))
    (I8# x# :: Int#
x#) shift :: Int8 -> Int -> Int8
`shift` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#) = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Int#
x# Int# -> Int# -> Int#
`iShiftL#` Int#
i#))
        | Bool
otherwise           = Int# -> Int8
I8# (Int#
x# Int# -> Int# -> Int#
`iShiftRA#` Int# -> Int#
negateInt# Int#
i#)
    (I8# x# :: Int#
x#) shiftL :: Int8 -> Int -> Int8
`shiftL`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#) = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Int#
x# Int# -> Int# -> Int#
`iShiftL#` Int#
i#))
        | Bool
otherwise           = Int8
forall a. a
overflowError
    (I8# x# :: Int#
x#) unsafeShiftL :: Int8 -> Int -> Int8
`unsafeShiftL` (I# i# :: Int#
i#) = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Int#
x# Int# -> Int# -> Int#
`uncheckedIShiftL#` Int#
i#))
    (I8# x# :: Int#
x#) shiftR :: Int8 -> Int -> Int8
`shiftR`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#) = Int# -> Int8
I8# (Int#
x# Int# -> Int# -> Int#
`iShiftRA#` Int#
i#)
        | Bool
otherwise           = Int8
forall a. a
overflowError
    (I8# x# :: Int#
x#) unsafeShiftR :: Int8 -> Int -> Int8
`unsafeShiftR` (I# i# :: Int#
i#) = Int# -> Int8
I8# (Int#
x# Int# -> Int# -> Int#
`uncheckedIShiftRA#` Int#
i#)
    (I8# x# :: Int#
x#) rotate :: Int8 -> Int -> Int8
`rotate` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# 0#)
        = Int# -> Int8
I8# Int#
x#
        | Bool
otherwise
        = Int# -> Int8
I8# (Int# -> Int#
narrow8Int# (Word# -> Int#
word2Int# ((Word#
x'# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i'#) Word# -> Word# -> Word#
`or#`
                                       (Word#
x'# Word# -> Int# -> Word#
`uncheckedShiftRL#` (8# Int# -> Int# -> Int#
-# Int#
i'#)))))
        where
        !x'# :: Word#
x'# = Word# -> Word#
narrow8Word# (Int# -> Word#
int2Word# Int#
x#)
        !i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` 7##)
    bitSizeMaybe :: Int8 -> Maybe Int
bitSizeMaybe i :: Int8
i            = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int8 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Int8
i)
    bitSize :: Int8 -> Int
bitSize i :: Int8
i                 = Int8 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Int8
i
    isSigned :: Int8 -> Bool
isSigned _                = Bool
True
    popCount :: Int8 -> Int
popCount (I8# x# :: Int#
x#)         = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
popCnt8# (Int# -> Word#
int2Word# Int#
x#)))
    bit :: Int -> Int8
bit                       = Int -> Int8
forall a. (Bits a, Num a) => Int -> a
bitDefault
    testBit :: Int8 -> Int -> Bool
testBit                   = Int8 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault

-- | @since 4.6.0.0
instance FiniteBits Int8 where
    finiteBitSize :: Int8 -> Int
finiteBitSize _ = 8
    countLeadingZeros :: Int8 -> Int
countLeadingZeros  (I8# x# :: Int#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz8# (Int# -> Word#
int2Word# Int#
x#)))
    countTrailingZeros :: Int8 -> Int
countTrailingZeros (I8# x# :: Int#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
ctz8# (Int# -> Word#
int2Word# Int#
x#)))

{-# RULES
"fromIntegral/Int8->Int8" fromIntegral = id :: Int8 -> Int8
"fromIntegral/a->Int8"    fromIntegral = \x -> case fromIntegral x of I# x# -> I8# (narrow8Int# x#)
"fromIntegral/Int8->a"    fromIntegral = \(I8# x#) -> fromIntegral (I# x#)
  #-}

{-# RULES
"properFraction/Float->(Int8,Float)"
    properFraction = \x ->
                      case properFraction x of {
                        (n, y) -> ((fromIntegral :: Int -> Int8) n, y :: Float) }
"truncate/Float->Int8"
    truncate = (fromIntegral :: Int -> Int8) . (truncate :: Float -> Int)
"floor/Float->Int8"
    floor    = (fromIntegral :: Int -> Int8) . (floor :: Float -> Int)
"ceiling/Float->Int8"
    ceiling  = (fromIntegral :: Int -> Int8) . (ceiling :: Float -> Int)
"round/Float->Int8"
    round    = (fromIntegral :: Int -> Int8) . (round  :: Float -> Int)
  #-}

{-# RULES
"properFraction/Double->(Int8,Double)"
    properFraction = \x ->
                      case properFraction x of {
                        (n, y) -> ((fromIntegral :: Int -> Int8) n, y :: Double) }
"truncate/Double->Int8"
    truncate = (fromIntegral :: Int -> Int8) . (truncate :: Double -> Int)
"floor/Double->Int8"
    floor    = (fromIntegral :: Int -> Int8) . (floor :: Double -> Int)
"ceiling/Double->Int8"
    ceiling  = (fromIntegral :: Int -> Int8) . (ceiling :: Double -> Int)
"round/Double->Int8"
    round    = (fromIntegral :: Int -> Int8) . (round  :: Double -> Int)
  #-}

------------------------------------------------------------------------
-- type Int16
------------------------------------------------------------------------

-- Int16 is represented in the same way as Int. Operations may assume
-- and must ensure that it holds only values from its logical range.

data {-# CTYPE "HsInt16" #-} Int16 = I16# Int#
-- ^ 16-bit signed integer type

-- See GHC.Classes#matching_overloaded_methods_in_rules
-- | @since 2.01
instance Eq Int16 where
    == :: Int16 -> Int16 -> Bool
(==) = Int16 -> Int16 -> Bool
eqInt16
    /= :: Int16 -> Int16 -> Bool
(/=) = Int16 -> Int16 -> Bool
neInt16

eqInt16, neInt16 :: Int16 -> Int16 -> Bool
eqInt16 :: Int16 -> Int16 -> Bool
eqInt16 (I16# x :: Int#
x) (I16# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
==# Int#
y)
neInt16 :: Int16 -> Int16 -> Bool
neInt16 (I16# x :: Int#
x) (I16# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
/=# Int#
y)
{-# INLINE [1] eqInt16 #-}
{-# INLINE [1] neInt16 #-}

-- | @since 2.01
instance Ord Int16 where
    < :: Int16 -> Int16 -> Bool
(<)  = Int16 -> Int16 -> Bool
ltInt16
    <= :: Int16 -> Int16 -> Bool
(<=) = Int16 -> Int16 -> Bool
leInt16
    >= :: Int16 -> Int16 -> Bool
(>=) = Int16 -> Int16 -> Bool
geInt16
    > :: Int16 -> Int16 -> Bool
(>)  = Int16 -> Int16 -> Bool
gtInt16

{-# INLINE [1] gtInt16 #-}
{-# INLINE [1] geInt16 #-}
{-# INLINE [1] ltInt16 #-}
{-# INLINE [1] leInt16 #-}
gtInt16, geInt16, ltInt16, leInt16 :: Int16 -> Int16 -> Bool
(I16# x :: Int#
x) gtInt16 :: Int16 -> Int16 -> Bool
`gtInt16` (I16# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
>#  Int#
y)
(I16# x :: Int#
x) geInt16 :: Int16 -> Int16 -> Bool
`geInt16` (I16# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
>=# Int#
y)
(I16# x :: Int#
x) ltInt16 :: Int16 -> Int16 -> Bool
`ltInt16` (I16# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
<#  Int#
y)
(I16# x :: Int#
x) leInt16 :: Int16 -> Int16 -> Bool
`leInt16` (I16# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
<=# Int#
y)

-- | @since 2.01
instance Show Int16 where
    showsPrec :: Int -> Int16 -> ShowS
showsPrec p :: Int
p x :: Int16
x = Int -> Int -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (Int16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int16
x :: Int)

-- | @since 2.01
instance Num Int16 where
    (I16# x# :: Int#
x#) + :: Int16 -> Int16 -> Int16
+ (I16# y# :: Int#
y#)  = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Int#
x# Int# -> Int# -> Int#
+# Int#
y#))
    (I16# x# :: Int#
x#) - :: Int16 -> Int16 -> Int16
- (I16# y# :: Int#
y#)  = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Int#
x# Int# -> Int# -> Int#
-# Int#
y#))
    (I16# x# :: Int#
x#) * :: Int16 -> Int16 -> Int16
* (I16# y# :: Int#
y#)  = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Int#
x# Int# -> Int# -> Int#
*# Int#
y#))
    negate :: Int16 -> Int16
negate (I16# x# :: Int#
x#)       = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Int# -> Int#
negateInt# Int#
x#))
    abs :: Int16 -> Int16
abs x :: Int16
x | Int16
x Int16 -> Int16 -> Bool
forall a. Ord a => a -> a -> Bool
>= 0         = Int16
x
          | Bool
otherwise      = Int16 -> Int16
forall a. Num a => a -> a
negate Int16
x
    signum :: Int16 -> Int16
signum x :: Int16
x | Int16
x Int16 -> Int16 -> Bool
forall a. Ord a => a -> a -> Bool
> 0       = 1
    signum 0               = 0
    signum _               = -1
    fromInteger :: Integer -> Int16
fromInteger i :: Integer
i          = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Integer -> Int#
integerToInt Integer
i))

-- | @since 2.01
instance Real Int16 where
    toRational :: Int16 -> Rational
toRational x :: Int16
x = Int16 -> Integer
forall a. Integral a => a -> Integer
toInteger Int16
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% 1

-- | @since 2.01
instance Enum Int16 where
    succ :: Int16 -> Int16
succ x :: Int16
x
        | Int16
x Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Int16
forall a. Bounded a => a
maxBound = Int16
x Int16 -> Int16 -> Int16
forall a. Num a => a -> a -> a
+ 1
        | Bool
otherwise     = String -> Int16
forall a. String -> a
succError "Int16"
    pred :: Int16 -> Int16
pred x :: Int16
x
        | Int16
x Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Int16
forall a. Bounded a => a
minBound = Int16
x Int16 -> Int16 -> Int16
forall a. Num a => a -> a -> a
- 1
        | Bool
otherwise     = String -> Int16
forall a. String -> a
predError "Int16"
    toEnum :: Int -> Int16
toEnum i :: Int
i@(I# i# :: Int#
i#)
        | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int16
forall a. Bounded a => a
minBound::Int16) Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int16
forall a. Bounded a => a
maxBound::Int16)
                        = Int# -> Int16
I16# Int#
i#
        | Bool
otherwise     = String -> Int -> (Int16, Int16) -> Int16
forall a b. Show a => String -> Int -> (a, a) -> b
toEnumError "Int16" Int
i (Int16
forall a. Bounded a => a
minBound::Int16, Int16
forall a. Bounded a => a
maxBound::Int16)
    fromEnum :: Int16 -> Int
fromEnum (I16# x# :: Int#
x#)  = Int# -> Int
I# Int#
x#
    enumFrom :: Int16 -> [Int16]
enumFrom            = Int16 -> [Int16]
forall a. (Enum a, Bounded a) => a -> [a]
boundedEnumFrom
    enumFromThen :: Int16 -> Int16 -> [Int16]
enumFromThen        = Int16 -> Int16 -> [Int16]
forall a. (Enum a, Bounded a) => a -> a -> [a]
boundedEnumFromThen

-- | @since 2.01
instance Integral Int16 where
    quot :: Int16 -> Int16 -> Int16
quot    x :: Int16
x@(I16# x# :: Int#
x#) y :: Int16
y@(I16# y# :: Int#
y#)
        | Int16
y Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int16
forall a. a
divZeroError
        | Int16
y Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int16
x Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== Int16
forall a. Bounded a => a
minBound = Int16
forall a. a
overflowError -- Note [Order of tests]
        | Bool
otherwise                  = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Int#
x# Int# -> Int# -> Int#
`quotInt#` Int#
y#))
    rem :: Int16 -> Int16 -> Int16
rem       (I16# x# :: Int#
x#) y :: Int16
y@(I16# y# :: Int#
y#)
        | Int16
y Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int16
forall a. a
divZeroError
        | Bool
otherwise                  = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Int#
x# Int# -> Int# -> Int#
`remInt#` Int#
y#))
    div :: Int16 -> Int16 -> Int16
div     x :: Int16
x@(I16# x# :: Int#
x#) y :: Int16
y@(I16# y# :: Int#
y#)
        | Int16
y Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int16
forall a. a
divZeroError
        | Int16
y Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int16
x Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== Int16
forall a. Bounded a => a
minBound = Int16
forall a. a
overflowError -- Note [Order of tests]
        | Bool
otherwise                  = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Int#
x# Int# -> Int# -> Int#
`divInt#` Int#
y#))
    mod :: Int16 -> Int16 -> Int16
mod       (I16# x# :: Int#
x#) y :: Int16
y@(I16# y# :: Int#
y#)
        | Int16
y Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int16
forall a. a
divZeroError
        | Bool
otherwise                  = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Int#
x# Int# -> Int# -> Int#
`modInt#` Int#
y#))
    quotRem :: Int16 -> Int16 -> (Int16, Int16)
quotRem x :: Int16
x@(I16# x# :: Int#
x#) y :: Int16
y@(I16# y# :: Int#
y#)
        | Int16
y Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = (Int16, Int16)
forall a. a
divZeroError
          -- Note [Order of tests]
        | Int16
y Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int16
x Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== Int16
forall a. Bounded a => a
minBound = (Int16
forall a. a
overflowError, 0)
        | Bool
otherwise                  = case Int#
x# Int# -> Int# -> (# Int#, Int# #)
`quotRemInt#` Int#
y# of
                                       (# q :: Int#
q, r :: Int#
r #) ->
                                           (Int# -> Int16
I16# (Int# -> Int#
narrow16Int# Int#
q),
                                            Int# -> Int16
I16# (Int# -> Int#
narrow16Int# Int#
r))
    divMod :: Int16 -> Int16 -> (Int16, Int16)
divMod  x :: Int16
x@(I16# x# :: Int#
x#) y :: Int16
y@(I16# y# :: Int#
y#)
        | Int16
y Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = (Int16, Int16)
forall a. a
divZeroError
          -- Note [Order of tests]
        | Int16
y Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int16
x Int16 -> Int16 -> Bool
forall a. Eq a => a -> a -> Bool
== Int16
forall a. Bounded a => a
minBound = (Int16
forall a. a
overflowError, 0)
        | Bool
otherwise                  = case Int#
x# Int# -> Int# -> (# Int#, Int# #)
`divModInt#` Int#
y# of
                                       (# d :: Int#
d, m :: Int#
m #) ->
                                           (Int# -> Int16
I16# (Int# -> Int#
narrow16Int# Int#
d),
                                            Int# -> Int16
I16# (Int# -> Int#
narrow16Int# Int#
m))
    toInteger :: Int16 -> Integer
toInteger (I16# x# :: Int#
x#)              = Int# -> Integer
smallInteger Int#
x#

-- | @since 2.01
instance Bounded Int16 where
    minBound :: Int16
minBound = -0x8000
    maxBound :: Int16
maxBound =  0x7FFF

-- | @since 2.01
instance Ix Int16 where
    range :: (Int16, Int16) -> [Int16]
range (m :: Int16
m,n :: Int16
n)         = [Int16
m..Int16
n]
    unsafeIndex :: (Int16, Int16) -> Int16 -> Int
unsafeIndex (m :: Int16
m,_) i :: Int16
i = Int16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int16
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int16
m
    inRange :: (Int16, Int16) -> Int16 -> Bool
inRange (m :: Int16
m,n :: Int16
n) i :: Int16
i     = Int16
m Int16 -> Int16 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int16
i Bool -> Bool -> Bool
&& Int16
i Int16 -> Int16 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int16
n

-- | @since 2.01
instance Read Int16 where
    readsPrec :: Int -> ReadS Int16
readsPrec p :: Int
p s :: String
s = [(Int -> Int16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
x::Int), String
r) | (x :: Int
x, r :: String
r) <- Int -> ReadS Int
forall a. Read a => Int -> ReadS a
readsPrec Int
p String
s]

-- | @since 2.01
instance Bits Int16 where
    {-# INLINE shift #-}
    {-# INLINE bit #-}
    {-# INLINE testBit #-}

    (I16# x# :: Int#
x#) .&. :: Int16 -> Int16 -> Int16
.&.   (I16# y# :: Int#
y#)  = Int# -> Int16
I16# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`and#` Int# -> Word#
int2Word# Int#
y#))
    (I16# x# :: Int#
x#) .|. :: Int16 -> Int16 -> Int16
.|.   (I16# y# :: Int#
y#)  = Int# -> Int16
I16# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`or#`  Int# -> Word#
int2Word# Int#
y#))
    (I16# x# :: Int#
x#) xor :: Int16 -> Int16 -> Int16
`xor` (I16# y# :: Int#
y#)  = Int# -> Int16
I16# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`xor#` Int# -> Word#
int2Word# Int#
y#))
    complement :: Int16 -> Int16
complement (I16# x# :: Int#
x#)       = Int# -> Int16
I16# (Word# -> Int#
word2Int# (Word# -> Word#
not# (Int# -> Word#
int2Word# Int#
x#)))
    (I16# x# :: Int#
x#) shift :: Int16 -> Int -> Int16
`shift` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Int#
x# Int# -> Int# -> Int#
`iShiftL#` Int#
i#))
        | Bool
otherwise            = Int# -> Int16
I16# (Int#
x# Int# -> Int# -> Int#
`iShiftRA#` Int# -> Int#
negateInt# Int#
i#)
    (I16# x# :: Int#
x#) shiftL :: Int16 -> Int -> Int16
`shiftL`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Int#
x# Int# -> Int# -> Int#
`iShiftL#` Int#
i#))
        | Bool
otherwise            = Int16
forall a. a
overflowError
    (I16# x# :: Int#
x#) unsafeShiftL :: Int16 -> Int -> Int16
`unsafeShiftL` (I# i# :: Int#
i#) = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Int#
x# Int# -> Int# -> Int#
`uncheckedIShiftL#` Int#
i#))
    (I16# x# :: Int#
x#) shiftR :: Int16 -> Int -> Int16
`shiftR`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Int# -> Int16
I16# (Int#
x# Int# -> Int# -> Int#
`iShiftRA#` Int#
i#)
        | Bool
otherwise            = Int16
forall a. a
overflowError
    (I16# x# :: Int#
x#) unsafeShiftR :: Int16 -> Int -> Int16
`unsafeShiftR` (I# i# :: Int#
i#) = Int# -> Int16
I16# (Int#
x# Int# -> Int# -> Int#
`uncheckedIShiftRA#` Int#
i#)
    (I16# x# :: Int#
x#) rotate :: Int16 -> Int -> Int16
`rotate` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# 0#)
        = Int# -> Int16
I16# Int#
x#
        | Bool
otherwise
        = Int# -> Int16
I16# (Int# -> Int#
narrow16Int# (Word# -> Int#
word2Int# ((Word#
x'# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i'#) Word# -> Word# -> Word#
`or#`
                                         (Word#
x'# Word# -> Int# -> Word#
`uncheckedShiftRL#` (16# Int# -> Int# -> Int#
-# Int#
i'#)))))
        where
        !x'# :: Word#
x'# = Word# -> Word#
narrow16Word# (Int# -> Word#
int2Word# Int#
x#)
        !i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` 15##)
    bitSizeMaybe :: Int16 -> Maybe Int
bitSizeMaybe i :: Int16
i             = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int16 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Int16
i)
    bitSize :: Int16 -> Int
bitSize i :: Int16
i                  = Int16 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Int16
i
    isSigned :: Int16 -> Bool
isSigned _                 = Bool
True
    popCount :: Int16 -> Int
popCount (I16# x# :: Int#
x#)         = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
popCnt16# (Int# -> Word#
int2Word# Int#
x#)))
    bit :: Int -> Int16
bit                        = Int -> Int16
forall a. (Bits a, Num a) => Int -> a
bitDefault
    testBit :: Int16 -> Int -> Bool
testBit                    = Int16 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault

-- | @since 4.6.0.0
instance FiniteBits Int16 where
    finiteBitSize :: Int16 -> Int
finiteBitSize _ = 16
    countLeadingZeros :: Int16 -> Int
countLeadingZeros  (I16# x# :: Int#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz16# (Int# -> Word#
int2Word# Int#
x#)))
    countTrailingZeros :: Int16 -> Int
countTrailingZeros (I16# x# :: Int#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
ctz16# (Int# -> Word#
int2Word# Int#
x#)))

{-# RULES
"fromIntegral/Word8->Int16"  fromIntegral = \(W8# x#) -> I16# (word2Int# x#)
"fromIntegral/Int8->Int16"   fromIntegral = \(I8# x#) -> I16# x#
"fromIntegral/Int16->Int16"  fromIntegral = id :: Int16 -> Int16
"fromIntegral/a->Int16"      fromIntegral = \x -> case fromIntegral x of I# x# -> I16# (narrow16Int# x#)
"fromIntegral/Int16->a"      fromIntegral = \(I16# x#) -> fromIntegral (I# x#)
  #-}

{-# RULES
"properFraction/Float->(Int16,Float)"
    properFraction = \x ->
                      case properFraction x of {
                        (n, y) -> ((fromIntegral :: Int -> Int16) n, y :: Float) }
"truncate/Float->Int16"
    truncate = (fromIntegral :: Int -> Int16) . (truncate :: Float -> Int)
"floor/Float->Int16"
    floor    = (fromIntegral :: Int -> Int16) . (floor :: Float -> Int)
"ceiling/Float->Int16"
    ceiling  = (fromIntegral :: Int -> Int16) . (ceiling :: Float -> Int)
"round/Float->Int16"
    round    = (fromIntegral :: Int -> Int16) . (round  :: Float -> Int)
  #-}

{-# RULES
"properFraction/Double->(Int16,Double)"
    properFraction = \x ->
                      case properFraction x of {
                        (n, y) -> ((fromIntegral :: Int -> Int16) n, y :: Double) }
"truncate/Double->Int16"
    truncate = (fromIntegral :: Int -> Int16) . (truncate :: Double -> Int)
"floor/Double->Int16"
    floor    = (fromIntegral :: Int -> Int16) . (floor :: Double -> Int)
"ceiling/Double->Int16"
    ceiling  = (fromIntegral :: Int -> Int16) . (ceiling :: Double -> Int)
"round/Double->Int16"
    round    = (fromIntegral :: Int -> Int16) . (round  :: Double -> Int)
  #-}

------------------------------------------------------------------------
-- type Int32
------------------------------------------------------------------------

-- Int32 is represented in the same way as Int.
#if WORD_SIZE_IN_BITS > 32
-- Operations may assume and must ensure that it holds only values
-- from its logical range.
#endif

data {-# CTYPE "HsInt32" #-} Int32 = I32# Int#
-- ^ 32-bit signed integer type

-- See GHC.Classes#matching_overloaded_methods_in_rules
-- | @since 2.01
instance Eq Int32 where
    == :: Int32 -> Int32 -> Bool
(==) = Int32 -> Int32 -> Bool
eqInt32
    /= :: Int32 -> Int32 -> Bool
(/=) = Int32 -> Int32 -> Bool
neInt32

eqInt32, neInt32 :: Int32 -> Int32 -> Bool
eqInt32 :: Int32 -> Int32 -> Bool
eqInt32 (I32# x :: Int#
x) (I32# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
==# Int#
y)
neInt32 :: Int32 -> Int32 -> Bool
neInt32 (I32# x :: Int#
x) (I32# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
/=# Int#
y)
{-# INLINE [1] eqInt32 #-}
{-# INLINE [1] neInt32 #-}

-- | @since 2.01
instance Ord Int32 where
    < :: Int32 -> Int32 -> Bool
(<)  = Int32 -> Int32 -> Bool
ltInt32
    <= :: Int32 -> Int32 -> Bool
(<=) = Int32 -> Int32 -> Bool
leInt32
    >= :: Int32 -> Int32 -> Bool
(>=) = Int32 -> Int32 -> Bool
geInt32
    > :: Int32 -> Int32 -> Bool
(>)  = Int32 -> Int32 -> Bool
gtInt32

{-# INLINE [1] gtInt32 #-}
{-# INLINE [1] geInt32 #-}
{-# INLINE [1] ltInt32 #-}
{-# INLINE [1] leInt32 #-}
gtInt32, geInt32, ltInt32, leInt32 :: Int32 -> Int32 -> Bool
(I32# x :: Int#
x) gtInt32 :: Int32 -> Int32 -> Bool
`gtInt32` (I32# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
>#  Int#
y)
(I32# x :: Int#
x) geInt32 :: Int32 -> Int32 -> Bool
`geInt32` (I32# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
>=# Int#
y)
(I32# x :: Int#
x) ltInt32 :: Int32 -> Int32 -> Bool
`ltInt32` (I32# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
<#  Int#
y)
(I32# x :: Int#
x) leInt32 :: Int32 -> Int32 -> Bool
`leInt32` (I32# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
<=# Int#
y)

-- | @since 2.01
instance Show Int32 where
    showsPrec :: Int -> Int32 -> ShowS
showsPrec p :: Int
p x :: Int32
x = Int -> Int -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
x :: Int)

-- | @since 2.01
instance Num Int32 where
    (I32# x# :: Int#
x#) + :: Int32 -> Int32 -> Int32
+ (I32# y# :: Int#
y#)  = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Int#
x# Int# -> Int# -> Int#
+# Int#
y#))
    (I32# x# :: Int#
x#) - :: Int32 -> Int32 -> Int32
- (I32# y# :: Int#
y#)  = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Int#
x# Int# -> Int# -> Int#
-# Int#
y#))
    (I32# x# :: Int#
x#) * :: Int32 -> Int32 -> Int32
* (I32# y# :: Int#
y#)  = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Int#
x# Int# -> Int# -> Int#
*# Int#
y#))
    negate :: Int32 -> Int32
negate (I32# x# :: Int#
x#)       = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Int# -> Int#
negateInt# Int#
x#))
    abs :: Int32 -> Int32
abs x :: Int32
x | Int32
x Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
>= 0         = Int32
x
          | Bool
otherwise      = Int32 -> Int32
forall a. Num a => a -> a
negate Int32
x
    signum :: Int32 -> Int32
signum x :: Int32
x | Int32
x Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
> 0       = 1
    signum 0               = 0
    signum _               = -1
    fromInteger :: Integer -> Int32
fromInteger i :: Integer
i          = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Integer -> Int#
integerToInt Integer
i))

-- | @since 2.01
instance Enum Int32 where
    succ :: Int32 -> Int32
succ x :: Int32
x
        | Int32
x Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Int32
forall a. Bounded a => a
maxBound = Int32
x Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ 1
        | Bool
otherwise     = String -> Int32
forall a. String -> a
succError "Int32"
    pred :: Int32 -> Int32
pred x :: Int32
x
        | Int32
x Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Int32
forall a. Bounded a => a
minBound = Int32
x Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
- 1
        | Bool
otherwise     = String -> Int32
forall a. String -> a
predError "Int32"
#if WORD_SIZE_IN_BITS == 32
    toEnum (I# i#)      = I32# i#
#else
    toEnum :: Int -> Int32
toEnum i :: Int
i@(I# i# :: Int#
i#)
        | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
forall a. Bounded a => a
minBound::Int32) Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
forall a. Bounded a => a
maxBound::Int32)
                        = Int# -> Int32
I32# Int#
i#
        | Bool
otherwise     = String -> Int -> (Int32, Int32) -> Int32
forall a b. Show a => String -> Int -> (a, a) -> b
toEnumError "Int32" Int
i (Int32
forall a. Bounded a => a
minBound::Int32, Int32
forall a. Bounded a => a
maxBound::Int32)
#endif
    fromEnum :: Int32 -> Int
fromEnum (I32# x# :: Int#
x#)  = Int# -> Int
I# Int#
x#
    enumFrom :: Int32 -> [Int32]
enumFrom            = Int32 -> [Int32]
forall a. (Enum a, Bounded a) => a -> [a]
boundedEnumFrom
    enumFromThen :: Int32 -> Int32 -> [Int32]
enumFromThen        = Int32 -> Int32 -> [Int32]
forall a. (Enum a, Bounded a) => a -> a -> [a]
boundedEnumFromThen

-- | @since 2.01
instance Integral Int32 where
    quot :: Int32 -> Int32 -> Int32
quot    x :: Int32
x@(I32# x# :: Int#
x#) y :: Int32
y@(I32# y# :: Int#
y#)
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int32
forall a. a
divZeroError
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int32
x Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== Int32
forall a. Bounded a => a
minBound = Int32
forall a. a
overflowError -- Note [Order of tests]
        | Bool
otherwise                  = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Int#
x# Int# -> Int# -> Int#
`quotInt#` Int#
y#))
    rem :: Int32 -> Int32 -> Int32
rem       (I32# x# :: Int#
x#) y :: Int32
y@(I32# y# :: Int#
y#)
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int32
forall a. a
divZeroError
          -- The quotRem CPU instruction fails for minBound `quotRem` -1,
          -- but minBound `rem` -1 is well-defined (0). We therefore
          -- special-case it.
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1)                  = 0
        | Bool
otherwise                  = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Int#
x# Int# -> Int# -> Int#
`remInt#` Int#
y#))
    div :: Int32 -> Int32 -> Int32
div     x :: Int32
x@(I32# x# :: Int#
x#) y :: Int32
y@(I32# y# :: Int#
y#)
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int32
forall a. a
divZeroError
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int32
x Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== Int32
forall a. Bounded a => a
minBound = Int32
forall a. a
overflowError -- Note [Order of tests]
        | Bool
otherwise                  = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Int#
x# Int# -> Int# -> Int#
`divInt#` Int#
y#))
    mod :: Int32 -> Int32 -> Int32
mod       (I32# x# :: Int#
x#) y :: Int32
y@(I32# y# :: Int#
y#)
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int32
forall a. a
divZeroError
          -- The divMod CPU instruction fails for minBound `divMod` -1,
          -- but minBound `mod` -1 is well-defined (0). We therefore
          -- special-case it.
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1)                  = 0
        | Bool
otherwise                  = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Int#
x# Int# -> Int# -> Int#
`modInt#` Int#
y#))
    quotRem :: Int32 -> Int32 -> (Int32, Int32)
quotRem x :: Int32
x@(I32# x# :: Int#
x#) y :: Int32
y@(I32# y# :: Int#
y#)
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = (Int32, Int32)
forall a. a
divZeroError
          -- Note [Order of tests]
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int32
x Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== Int32
forall a. Bounded a => a
minBound = (Int32
forall a. a
overflowError, 0)
        | Bool
otherwise                  = case Int#
x# Int# -> Int# -> (# Int#, Int# #)
`quotRemInt#` Int#
y# of
                                       (# q :: Int#
q, r :: Int#
r #) ->
                                           (Int# -> Int32
I32# (Int# -> Int#
narrow32Int# Int#
q),
                                            Int# -> Int32
I32# (Int# -> Int#
narrow32Int# Int#
r))
    divMod :: Int32 -> Int32 -> (Int32, Int32)
divMod  x :: Int32
x@(I32# x# :: Int#
x#) y :: Int32
y@(I32# y# :: Int#
y#)
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = (Int32, Int32)
forall a. a
divZeroError
          -- Note [Order of tests]
        | Int32
y Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int32
x Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== Int32
forall a. Bounded a => a
minBound = (Int32
forall a. a
overflowError, 0)
        | Bool
otherwise                  = case Int#
x# Int# -> Int# -> (# Int#, Int# #)
`divModInt#` Int#
y# of
                                       (# d :: Int#
d, m :: Int#
m #) ->
                                           (Int# -> Int32
I32# (Int# -> Int#
narrow32Int# Int#
d),
                                            Int# -> Int32
I32# (Int# -> Int#
narrow32Int# Int#
m))
    toInteger :: Int32 -> Integer
toInteger (I32# x# :: Int#
x#)              = Int# -> Integer
smallInteger Int#
x#

-- | @since 2.01
instance Read Int32 where
    readsPrec :: Int -> ReadS Int32
readsPrec p :: Int
p s :: String
s = [(Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
x::Int), String
r) | (x :: Int
x, r :: String
r) <- Int -> ReadS Int
forall a. Read a => Int -> ReadS a
readsPrec Int
p String
s]

-- | @since 2.01
instance Bits Int32 where
    {-# INLINE shift #-}
    {-# INLINE bit #-}
    {-# INLINE testBit #-}

    (I32# x# :: Int#
x#) .&. :: Int32 -> Int32 -> Int32
.&.   (I32# y# :: Int#
y#)  = Int# -> Int32
I32# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`and#` Int# -> Word#
int2Word# Int#
y#))
    (I32# x# :: Int#
x#) .|. :: Int32 -> Int32 -> Int32
.|.   (I32# y# :: Int#
y#)  = Int# -> Int32
I32# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`or#`  Int# -> Word#
int2Word# Int#
y#))
    (I32# x# :: Int#
x#) xor :: Int32 -> Int32 -> Int32
`xor` (I32# y# :: Int#
y#)  = Int# -> Int32
I32# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`xor#` Int# -> Word#
int2Word# Int#
y#))
    complement :: Int32 -> Int32
complement (I32# x# :: Int#
x#)       = Int# -> Int32
I32# (Word# -> Int#
word2Int# (Word# -> Word#
not# (Int# -> Word#
int2Word# Int#
x#)))
    (I32# x# :: Int#
x#) shift :: Int32 -> Int -> Int32
`shift` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Int#
x# Int# -> Int# -> Int#
`iShiftL#` Int#
i#))
        | Bool
otherwise            = Int# -> Int32
I32# (Int#
x# Int# -> Int# -> Int#
`iShiftRA#` Int# -> Int#
negateInt# Int#
i#)
    (I32# x# :: Int#
x#) shiftL :: Int32 -> Int -> Int32
`shiftL`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Int#
x# Int# -> Int# -> Int#
`iShiftL#` Int#
i#))
        | Bool
otherwise            = Int32
forall a. a
overflowError
    (I32# x# :: Int#
x#) unsafeShiftL :: Int32 -> Int -> Int32
`unsafeShiftL` (I# i# :: Int#
i#) =
        Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Int#
x# Int# -> Int# -> Int#
`uncheckedIShiftL#` Int#
i#))
    (I32# x# :: Int#
x#) shiftR :: Int32 -> Int -> Int32
`shiftR`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Int# -> Int32
I32# (Int#
x# Int# -> Int# -> Int#
`iShiftRA#` Int#
i#)
        | Bool
otherwise            = Int32
forall a. a
overflowError
    (I32# x# :: Int#
x#) unsafeShiftR :: Int32 -> Int -> Int32
`unsafeShiftR` (I# i# :: Int#
i#) = Int# -> Int32
I32# (Int#
x# Int# -> Int# -> Int#
`uncheckedIShiftRA#` Int#
i#)
    (I32# x# :: Int#
x#) rotate :: Int32 -> Int -> Int32
`rotate` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# 0#)
        = Int# -> Int32
I32# Int#
x#
        | Bool
otherwise
        = Int# -> Int32
I32# (Int# -> Int#
narrow32Int# (Word# -> Int#
word2Int# ((Word#
x'# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i'#) Word# -> Word# -> Word#
`or#`
                                         (Word#
x'# Word# -> Int# -> Word#
`uncheckedShiftRL#` (32# Int# -> Int# -> Int#
-# Int#
i'#)))))
        where
        !x'# :: Word#
x'# = Word# -> Word#
narrow32Word# (Int# -> Word#
int2Word# Int#
x#)
        !i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` 31##)
    bitSizeMaybe :: Int32 -> Maybe Int
bitSizeMaybe i :: Int32
i             = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int32 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Int32
i)
    bitSize :: Int32 -> Int
bitSize i :: Int32
i                  = Int32 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Int32
i
    isSigned :: Int32 -> Bool
isSigned _                 = Bool
True
    popCount :: Int32 -> Int
popCount (I32# x# :: Int#
x#)         = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
popCnt32# (Int# -> Word#
int2Word# Int#
x#)))
    bit :: Int -> Int32
bit                        = Int -> Int32
forall a. (Bits a, Num a) => Int -> a
bitDefault
    testBit :: Int32 -> Int -> Bool
testBit                    = Int32 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault

-- | @since 4.6.0.0
instance FiniteBits Int32 where
    finiteBitSize :: Int32 -> Int
finiteBitSize _ = 32
    countLeadingZeros :: Int32 -> Int
countLeadingZeros  (I32# x# :: Int#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz32# (Int# -> Word#
int2Word# Int#
x#)))
    countTrailingZeros :: Int32 -> Int
countTrailingZeros (I32# x# :: Int#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
ctz32# (Int# -> Word#
int2Word# Int#
x#)))

{-# RULES
"fromIntegral/Word8->Int32"  fromIntegral = \(W8# x#) -> I32# (word2Int# x#)
"fromIntegral/Word16->Int32" fromIntegral = \(W16# x#) -> I32# (word2Int# x#)
"fromIntegral/Int8->Int32"   fromIntegral = \(I8# x#) -> I32# x#
"fromIntegral/Int16->Int32"  fromIntegral = \(I16# x#) -> I32# x#
"fromIntegral/Int32->Int32"  fromIntegral = id :: Int32 -> Int32
"fromIntegral/a->Int32"      fromIntegral = \x -> case fromIntegral x of I# x# -> I32# (narrow32Int# x#)
"fromIntegral/Int32->a"      fromIntegral = \(I32# x#) -> fromIntegral (I# x#)
  #-}

{-# RULES
"properFraction/Float->(Int32,Float)"
    properFraction = \x ->
                      case properFraction x of {
                        (n, y) -> ((fromIntegral :: Int -> Int32) n, y :: Float) }
"truncate/Float->Int32"
    truncate = (fromIntegral :: Int -> Int32) . (truncate :: Float -> Int)
"floor/Float->Int32"
    floor    = (fromIntegral :: Int -> Int32) . (floor :: Float -> Int)
"ceiling/Float->Int32"
    ceiling  = (fromIntegral :: Int -> Int32) . (ceiling :: Float -> Int)
"round/Float->Int32"
    round    = (fromIntegral :: Int -> Int32) . (round  :: Float -> Int)
  #-}

{-# RULES
"properFraction/Double->(Int32,Double)"
    properFraction = \x ->
                      case properFraction x of {
                        (n, y) -> ((fromIntegral :: Int -> Int32) n, y :: Double) }
"truncate/Double->Int32"
    truncate = (fromIntegral :: Int -> Int32) . (truncate :: Double -> Int)
"floor/Double->Int32"
    floor    = (fromIntegral :: Int -> Int32) . (floor :: Double -> Int)
"ceiling/Double->Int32"
    ceiling  = (fromIntegral :: Int -> Int32) . (ceiling :: Double -> Int)
"round/Double->Int32"
    round    = (fromIntegral :: Int -> Int32) . (round  :: Double -> Int)
  #-}

-- | @since 2.01
instance Real Int32 where
    toRational :: Int32 -> Rational
toRational x :: Int32
x = Int32 -> Integer
forall a. Integral a => a -> Integer
toInteger Int32
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% 1

-- | @since 2.01
instance Bounded Int32 where
    minBound :: Int32
minBound = -0x80000000
    maxBound :: Int32
maxBound =  0x7FFFFFFF

-- | @since 2.01
instance Ix Int32 where
    range :: (Int32, Int32) -> [Int32]
range (m :: Int32
m,n :: Int32
n)         = [Int32
m..Int32
n]
    unsafeIndex :: (Int32, Int32) -> Int32 -> Int
unsafeIndex (m :: Int32
m,_) i :: Int32
i = Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
m
    inRange :: (Int32, Int32) -> Int32 -> Bool
inRange (m :: Int32
m,n :: Int32
n) i :: Int32
i     = Int32
m Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int32
i Bool -> Bool -> Bool
&& Int32
i Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int32
n

------------------------------------------------------------------------
-- type Int64
------------------------------------------------------------------------

#if WORD_SIZE_IN_BITS < 64

data {-# CTYPE "HsInt64" #-} Int64 = I64# Int64#
-- ^ 64-bit signed integer type

-- See GHC.Classes#matching_overloaded_methods_in_rules
-- | @since 2.01
instance Eq Int64 where
    (==) = eqInt64
    (/=) = neInt64

eqInt64, neInt64 :: Int64 -> Int64 -> Bool
eqInt64 (I64# x) (I64# y) = isTrue# (x `eqInt64#` y)
neInt64 (I64# x) (I64# y) = isTrue# (x `neInt64#` y)
{-# INLINE [1] eqInt64 #-}
{-# INLINE [1] neInt64 #-}

-- | @since 2.01
instance Ord Int64 where
    (<)  = ltInt64
    (<=) = leInt64
    (>=) = geInt64
    (>)  = gtInt64

{-# INLINE [1] gtInt64 #-}
{-# INLINE [1] geInt64 #-}
{-# INLINE [1] ltInt64 #-}
{-# INLINE [1] leInt64 #-}
gtInt64, geInt64, ltInt64, leInt64 :: Int64 -> Int64 -> Bool
(I64# x) `gtInt64` (I64# y) = isTrue# (x `gtInt64#` y)
(I64# x) `geInt64` (I64# y) = isTrue# (x `geInt64#` y)
(I64# x) `ltInt64` (I64# y) = isTrue# (x `ltInt64#` y)
(I64# x) `leInt64` (I64# y) = isTrue# (x `leInt64#` y)

-- | @since 2.01
instance Show Int64 where
    showsPrec p x = showsPrec p (toInteger x)

-- | @since 2.01
instance Num Int64 where
    (I64# x#) + (I64# y#)  = I64# (x# `plusInt64#`  y#)
    (I64# x#) - (I64# y#)  = I64# (x# `minusInt64#` y#)
    (I64# x#) * (I64# y#)  = I64# (x# `timesInt64#` y#)
    negate (I64# x#)       = I64# (negateInt64# x#)
    abs x | x >= 0         = x
          | otherwise      = negate x
    signum x | x > 0       = 1
    signum 0               = 0
    signum _               = -1
    fromInteger i          = I64# (integerToInt64 i)

-- | @since 2.01
instance Enum Int64 where
    succ x
        | x /= maxBound = x + 1
        | otherwise     = succError "Int64"
    pred x
        | x /= minBound = x - 1
        | otherwise     = predError "Int64"
    toEnum (I# i#)      = I64# (intToInt64# i#)
    fromEnum x@(I64# x#)
        | x >= fromIntegral (minBound::Int) && x <= fromIntegral (maxBound::Int)
                        = I# (int64ToInt# x#)
        | otherwise     = fromEnumError "Int64" x
    enumFrom            = integralEnumFrom
    enumFromThen        = integralEnumFromThen
    enumFromTo          = integralEnumFromTo
    enumFromThenTo      = integralEnumFromThenTo

-- | @since 2.01
instance Integral Int64 where
    quot    x@(I64# x#) y@(I64# y#)
        | y == 0                     = divZeroError
        | y == (-1) && x == minBound = overflowError -- Note [Order of tests]
        | otherwise                  = I64# (x# `quotInt64#` y#)
    rem       (I64# x#) y@(I64# y#)
        | y == 0                     = divZeroError
          -- The quotRem CPU instruction fails for minBound `quotRem` -1,
          -- but minBound `rem` -1 is well-defined (0). We therefore
          -- special-case it.
        | y == (-1)                  = 0
        | otherwise                  = I64# (x# `remInt64#` y#)
    div     x@(I64# x#) y@(I64# y#)
        | y == 0                     = divZeroError
        | y == (-1) && x == minBound = overflowError -- Note [Order of tests]
        | otherwise                  = I64# (x# `divInt64#` y#)
    mod       (I64# x#) y@(I64# y#)
        | y == 0                     = divZeroError
          -- The divMod CPU instruction fails for minBound `divMod` -1,
          -- but minBound `mod` -1 is well-defined (0). We therefore
          -- special-case it.
        | y == (-1)                  = 0
        | otherwise                  = I64# (x# `modInt64#` y#)
    quotRem x@(I64# x#) y@(I64# y#)
        | y == 0                     = divZeroError
          -- Note [Order of tests]
        | y == (-1) && x == minBound = (overflowError, 0)
        | otherwise                  = (I64# (x# `quotInt64#` y#),
                                        I64# (x# `remInt64#` y#))
    divMod  x@(I64# x#) y@(I64# y#)
        | y == 0                     = divZeroError
          -- Note [Order of tests]
        | y == (-1) && x == minBound = (overflowError, 0)
        | otherwise                  = (I64# (x# `divInt64#` y#),
                                        I64# (x# `modInt64#` y#))
    toInteger (I64# x)               = int64ToInteger x


divInt64#, modInt64# :: Int64# -> Int64# -> Int64#

-- Define div in terms of quot, being careful to avoid overflow (#7233)
x# `divInt64#` y#
    | isTrue# (x# `gtInt64#` zero) && isTrue# (y# `ltInt64#` zero)
        = ((x# `minusInt64#` one) `quotInt64#` y#) `minusInt64#` one
    | isTrue# (x# `ltInt64#` zero) && isTrue# (y# `gtInt64#` zero)
        = ((x# `plusInt64#` one)  `quotInt64#` y#) `minusInt64#` one
    | otherwise
        = x# `quotInt64#` y#
    where
    !zero = intToInt64# 0#
    !one  = intToInt64# 1#

x# `modInt64#` y#
    | isTrue# (x# `gtInt64#` zero) && isTrue# (y# `ltInt64#` zero) ||
      isTrue# (x# `ltInt64#` zero) && isTrue# (y# `gtInt64#` zero)
        = if isTrue# (r# `neInt64#` zero) then r# `plusInt64#` y# else zero
    | otherwise = r#
    where
    !zero = intToInt64# 0#
    !r# = x# `remInt64#` y#

-- | @since 2.01
instance Read Int64 where
    readsPrec p s = [(fromInteger x, r) | (x, r) <- readsPrec p s]

-- | @since 2.01
instance Bits Int64 where
    {-# INLINE shift #-}
    {-# INLINE bit #-}
    {-# INLINE testBit #-}

    (I64# x#) .&.   (I64# y#)  = I64# (word64ToInt64# (int64ToWord64# x# `and64#` int64ToWord64# y#))
    (I64# x#) .|.   (I64# y#)  = I64# (word64ToInt64# (int64ToWord64# x# `or64#`  int64ToWord64# y#))
    (I64# x#) `xor` (I64# y#)  = I64# (word64ToInt64# (int64ToWord64# x# `xor64#` int64ToWord64# y#))
    complement (I64# x#)       = I64# (word64ToInt64# (not64# (int64ToWord64# x#)))
    (I64# x#) `shift` (I# i#)
        | isTrue# (i# >=# 0#)  = I64# (x# `iShiftL64#` i#)
        | otherwise            = I64# (x# `iShiftRA64#` negateInt# i#)
    (I64# x#) `shiftL` (I# i#)
        | isTrue# (i# >=# 0#)  = I64# (x# `iShiftL64#` i#)
        | otherwise            = overflowError
    (I64# x#) `unsafeShiftL` (I# i#) = I64# (x# `uncheckedIShiftL64#` i#)
    (I64# x#) `shiftR` (I# i#)
        | isTrue# (i# >=# 0#)  = I64# (x# `iShiftRA64#` i#)
        | otherwise            = overflowError
    (I64# x#) `unsafeShiftR` (I# i#) = I64# (x# `uncheckedIShiftRA64#` i#)
    (I64# x#) `rotate` (I# i#)
        | isTrue# (i'# ==# 0#)
        = I64# x#
        | otherwise
        = I64# (word64ToInt64# ((x'# `uncheckedShiftL64#` i'#) `or64#`
                                (x'# `uncheckedShiftRL64#` (64# -# i'#))))
        where
        !x'# = int64ToWord64# x#
        !i'# = word2Int# (int2Word# i# `and#` 63##)
    bitSizeMaybe i             = Just (finiteBitSize i)
    bitSize i                  = finiteBitSize i
    isSigned _                 = True
    popCount (I64# x#)         =
        I# (word2Int# (popCnt64# (int64ToWord64# x#)))
    bit                        = bitDefault
    testBit                    = testBitDefault

-- give the 64-bit shift operations the same treatment as the 32-bit
-- ones (see GHC.Base), namely we wrap them in tests to catch the
-- cases when we're shifting more than 64 bits to avoid unspecified
-- behaviour in the C shift operations.

iShiftL64#, iShiftRA64# :: Int64# -> Int# -> Int64#

a `iShiftL64#` b  | isTrue# (b >=# 64#) = intToInt64# 0#
                  | otherwise           = a `uncheckedIShiftL64#` b

a `iShiftRA64#` b | isTrue# (b >=# 64#) = if isTrue# (a `ltInt64#` (intToInt64# 0#))
                                          then intToInt64# (-1#)
                                          else intToInt64# 0#
                  | otherwise = a `uncheckedIShiftRA64#` b

{-# RULES
"fromIntegral/Int->Int64"    fromIntegral = \(I#   x#) -> I64# (intToInt64# x#)
"fromIntegral/Word->Int64"   fromIntegral = \(W#   x#) -> I64# (word64ToInt64# (wordToWord64# x#))
"fromIntegral/Word64->Int64" fromIntegral = \(W64# x#) -> I64# (word64ToInt64# x#)
"fromIntegral/Int64->Int"    fromIntegral = \(I64# x#) -> I#   (int64ToInt# x#)
"fromIntegral/Int64->Word"   fromIntegral = \(I64# x#) -> W#   (int2Word# (int64ToInt# x#))
"fromIntegral/Int64->Word64" fromIntegral = \(I64# x#) -> W64# (int64ToWord64# x#)
"fromIntegral/Int64->Int64"  fromIntegral = id :: Int64 -> Int64
  #-}

-- No RULES for RealFrac methods if Int is smaller than Int64, we can't
-- go through Int and whether going through Integer is faster is uncertain.
#else

-- Int64 is represented in the same way as Int.
-- Operations may assume and must ensure that it holds only values
-- from its logical range.

data {-# CTYPE "HsInt64" #-} Int64 = I64# Int#
-- ^ 64-bit signed integer type

-- See GHC.Classes#matching_overloaded_methods_in_rules
-- | @since 2.01
instance Eq Int64 where
    == :: Int64 -> Int64 -> Bool
(==) = Int64 -> Int64 -> Bool
eqInt64
    /= :: Int64 -> Int64 -> Bool
(/=) = Int64 -> Int64 -> Bool
neInt64

eqInt64, neInt64 :: Int64 -> Int64 -> Bool
eqInt64 :: Int64 -> Int64 -> Bool
eqInt64 (I64# x :: Int#
x) (I64# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
==# Int#
y)
neInt64 :: Int64 -> Int64 -> Bool
neInt64 (I64# x :: Int#
x) (I64# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
/=# Int#
y)
{-# INLINE [1] eqInt64 #-}
{-# INLINE [1] neInt64 #-}

-- | @since 2.01
instance Ord Int64 where
    < :: Int64 -> Int64 -> Bool
(<)  = Int64 -> Int64 -> Bool
ltInt64
    <= :: Int64 -> Int64 -> Bool
(<=) = Int64 -> Int64 -> Bool
leInt64
    >= :: Int64 -> Int64 -> Bool
(>=) = Int64 -> Int64 -> Bool
geInt64
    > :: Int64 -> Int64 -> Bool
(>)  = Int64 -> Int64 -> Bool
gtInt64

{-# INLINE [1] gtInt64 #-}
{-# INLINE [1] geInt64 #-}
{-# INLINE [1] ltInt64 #-}
{-# INLINE [1] leInt64 #-}
gtInt64, geInt64, ltInt64, leInt64 :: Int64 -> Int64 -> Bool
(I64# x :: Int#
x) gtInt64 :: Int64 -> Int64 -> Bool
`gtInt64` (I64# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
>#  Int#
y)
(I64# x :: Int#
x) geInt64 :: Int64 -> Int64 -> Bool
`geInt64` (I64# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
>=# Int#
y)
(I64# x :: Int#
x) ltInt64 :: Int64 -> Int64 -> Bool
`ltInt64` (I64# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
<#  Int#
y)
(I64# x :: Int#
x) leInt64 :: Int64 -> Int64 -> Bool
`leInt64` (I64# y :: Int#
y) = Int# -> Bool
isTrue# (Int#
x Int# -> Int# -> Int#
<=# Int#
y)

-- | @since 2.01
instance Show Int64 where
    showsPrec :: Int -> Int64 -> ShowS
showsPrec p :: Int
p x :: Int64
x = Int -> Int -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
x :: Int)

-- | @since 2.01
instance Num Int64 where
    (I64# x# :: Int#
x#) + :: Int64 -> Int64 -> Int64
+ (I64# y# :: Int#
y#)  = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
+# Int#
y#)
    (I64# x# :: Int#
x#) - :: Int64 -> Int64 -> Int64
- (I64# y# :: Int#
y#)  = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
-# Int#
y#)
    (I64# x# :: Int#
x#) * :: Int64 -> Int64 -> Int64
* (I64# y# :: Int#
y#)  = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
*# Int#
y#)
    negate :: Int64 -> Int64
negate (I64# x# :: Int#
x#)       = Int# -> Int64
I64# (Int# -> Int#
negateInt# Int#
x#)
    abs :: Int64 -> Int64
abs x :: Int64
x | Int64
x Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
>= 0         = Int64
x
          | Bool
otherwise      = Int64 -> Int64
forall a. Num a => a -> a
negate Int64
x
    signum :: Int64 -> Int64
signum x :: Int64
x | Int64
x Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
> 0       = 1
    signum 0               = 0
    signum _               = -1
    fromInteger :: Integer -> Int64
fromInteger i :: Integer
i          = Int# -> Int64
I64# (Integer -> Int#
integerToInt Integer
i)

-- | @since 2.01
instance Enum Int64 where
    succ :: Int64 -> Int64
succ x :: Int64
x
        | Int64
x Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Int64
forall a. Bounded a => a
maxBound = Int64
x Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ 1
        | Bool
otherwise     = String -> Int64
forall a. String -> a
succError "Int64"
    pred :: Int64 -> Int64
pred x :: Int64
x
        | Int64
x Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Int64
forall a. Bounded a => a
minBound = Int64
x Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- 1
        | Bool
otherwise     = String -> Int64
forall a. String -> a
predError "Int64"
    toEnum :: Int -> Int64
toEnum (I# i# :: Int#
i#)      = Int# -> Int64
I64# Int#
i#
    fromEnum :: Int64 -> Int
fromEnum (I64# x# :: Int#
x#)  = Int# -> Int
I# Int#
x#
    enumFrom :: Int64 -> [Int64]
enumFrom            = Int64 -> [Int64]
forall a. (Enum a, Bounded a) => a -> [a]
boundedEnumFrom
    enumFromThen :: Int64 -> Int64 -> [Int64]
enumFromThen        = Int64 -> Int64 -> [Int64]
forall a. (Enum a, Bounded a) => a -> a -> [a]
boundedEnumFromThen

-- | @since 2.01
instance Integral Int64 where
    quot :: Int64 -> Int64 -> Int64
quot    x :: Int64
x@(I64# x# :: Int#
x#) y :: Int64
y@(I64# y# :: Int#
y#)
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int64
forall a. a
divZeroError
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int64
x Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
forall a. Bounded a => a
minBound = Int64
forall a. a
overflowError -- Note [Order of tests]
        | Bool
otherwise                  = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
`quotInt#` Int#
y#)
    rem :: Int64 -> Int64 -> Int64
rem       (I64# x# :: Int#
x#) y :: Int64
y@(I64# y# :: Int#
y#)
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int64
forall a. a
divZeroError
          -- The quotRem CPU instruction fails for minBound `quotRem` -1,
          -- but minBound `rem` -1 is well-defined (0). We therefore
          -- special-case it.
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1)                  = 0
        | Bool
otherwise                  = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
`remInt#` Int#
y#)
    div :: Int64 -> Int64 -> Int64
div     x :: Int64
x@(I64# x# :: Int#
x#) y :: Int64
y@(I64# y# :: Int#
y#)
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int64
forall a. a
divZeroError
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int64
x Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
forall a. Bounded a => a
minBound = Int64
forall a. a
overflowError -- Note [Order of tests]
        | Bool
otherwise                  = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
`divInt#` Int#
y#)
    mod :: Int64 -> Int64 -> Int64
mod       (I64# x# :: Int#
x#) y :: Int64
y@(I64# y# :: Int#
y#)
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = Int64
forall a. a
divZeroError
          -- The divMod CPU instruction fails for minBound `divMod` -1,
          -- but minBound `mod` -1 is well-defined (0). We therefore
          -- special-case it.
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1)                  = 0
        | Bool
otherwise                  = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
`modInt#` Int#
y#)
    quotRem :: Int64 -> Int64 -> (Int64, Int64)
quotRem x :: Int64
x@(I64# x# :: Int#
x#) y :: Int64
y@(I64# y# :: Int#
y#)
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = (Int64, Int64)
forall a. a
divZeroError
          -- Note [Order of tests]
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int64
x Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
forall a. Bounded a => a
minBound = (Int64
forall a. a
overflowError, 0)
        | Bool
otherwise                  = case Int#
x# Int# -> Int# -> (# Int#, Int# #)
`quotRemInt#` Int#
y# of
                                       (# q :: Int#
q, r :: Int#
r #) ->
                                           (Int# -> Int64
I64# Int#
q, Int# -> Int64
I64# Int#
r)
    divMod :: Int64 -> Int64 -> (Int64, Int64)
divMod  x :: Int64
x@(I64# x# :: Int#
x#) y :: Int64
y@(I64# y# :: Int#
y#)
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== 0                     = (Int64, Int64)
forall a. a
divZeroError
          -- Note [Order of tests]
        | Int64
y Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== (-1) Bool -> Bool -> Bool
&& Int64
x Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
forall a. Bounded a => a
minBound = (Int64
forall a. a
overflowError, 0)
        | Bool
otherwise                  = case Int#
x# Int# -> Int# -> (# Int#, Int# #)
`divModInt#` Int#
y# of
                                       (# d :: Int#
d, m :: Int#
m #) ->
                                           (Int# -> Int64
I64# Int#
d, Int# -> Int64
I64# Int#
m)
    toInteger :: Int64 -> Integer
toInteger (I64# x# :: Int#
x#)              = Int# -> Integer
smallInteger Int#
x#

-- | @since 2.01
instance Read Int64 where
    readsPrec :: Int -> ReadS Int64
readsPrec p :: Int
p s :: String
s = [(Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
x::Int), String
r) | (x :: Int
x, r :: String
r) <- Int -> ReadS Int
forall a. Read a => Int -> ReadS a
readsPrec Int
p String
s]

-- | @since 2.01
instance Bits Int64 where
    {-# INLINE shift #-}
    {-# INLINE bit #-}
    {-# INLINE testBit #-}

    (I64# x# :: Int#
x#) .&. :: Int64 -> Int64 -> Int64
.&.   (I64# y# :: Int#
y#)  = Int# -> Int64
I64# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`and#` Int# -> Word#
int2Word# Int#
y#))
    (I64# x# :: Int#
x#) .|. :: Int64 -> Int64 -> Int64
.|.   (I64# y# :: Int#
y#)  = Int# -> Int64
I64# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`or#`  Int# -> Word#
int2Word# Int#
y#))
    (I64# x# :: Int#
x#) xor :: Int64 -> Int64 -> Int64
`xor` (I64# y# :: Int#
y#)  = Int# -> Int64
I64# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`xor#` Int# -> Word#
int2Word# Int#
y#))
    complement :: Int64 -> Int64
complement (I64# x# :: Int#
x#)       = Int# -> Int64
I64# (Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
x# Word# -> Word# -> Word#
`xor#` Int# -> Word#
int2Word# (-1#)))
    (I64# x# :: Int#
x#) shift :: Int64 -> Int -> Int64
`shift` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
`iShiftL#` Int#
i#)
        | Bool
otherwise            = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
`iShiftRA#` Int# -> Int#
negateInt# Int#
i#)
    (I64# x# :: Int#
x#) shiftL :: Int64 -> Int -> Int64
`shiftL`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
`iShiftL#` Int#
i#)
        | Bool
otherwise            = Int64
forall a. a
overflowError
    (I64# x# :: Int#
x#) unsafeShiftL :: Int64 -> Int -> Int64
`unsafeShiftL` (I# i# :: Int#
i#) = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
`uncheckedIShiftL#` Int#
i#)
    (I64# x# :: Int#
x#) shiftR :: Int64 -> Int -> Int64
`shiftR`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
`iShiftRA#` Int#
i#)
        | Bool
otherwise            = Int64
forall a. a
overflowError
    (I64# x# :: Int#
x#) unsafeShiftR :: Int64 -> Int -> Int64
`unsafeShiftR` (I# i# :: Int#
i#) = Int# -> Int64
I64# (Int#
x# Int# -> Int# -> Int#
`uncheckedIShiftRA#` Int#
i#)
    (I64# x# :: Int#
x#) rotate :: Int64 -> Int -> Int64
`rotate` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# 0#)
        = Int# -> Int64
I64# Int#
x#
        | Bool
otherwise
        = Int# -> Int64
I64# (Word# -> Int#
word2Int# ((Word#
x'# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i'#) Word# -> Word# -> Word#
`or#`
                           (Word#
x'# Word# -> Int# -> Word#
`uncheckedShiftRL#` (64# Int# -> Int# -> Int#
-# Int#
i'#))))
        where
        !x'# :: Word#
x'# = Int# -> Word#
int2Word# Int#
x#
        !i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` 63##)
    bitSizeMaybe :: Int64 -> Maybe Int
bitSizeMaybe i :: Int64
i             = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int64 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Int64
i)
    bitSize :: Int64 -> Int
bitSize i :: Int64
i                  = Int64 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Int64
i
    isSigned :: Int64 -> Bool
isSigned _                 = Bool
True
    popCount :: Int64 -> Int
popCount (I64# x# :: Int#
x#)         = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
popCnt64# (Int# -> Word#
int2Word# Int#
x#)))
    bit :: Int -> Int64
bit                        = Int -> Int64
forall a. (Bits a, Num a) => Int -> a
bitDefault
    testBit :: Int64 -> Int -> Bool
testBit                    = Int64 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault

{-# RULES
"fromIntegral/a->Int64" fromIntegral = \x -> case fromIntegral x of I# x# -> I64# x#
"fromIntegral/Int64->a" fromIntegral = \(I64# x#) -> fromIntegral (I# x#)
  #-}

{-# RULES
"properFraction/Float->(Int64,Float)"
    properFraction = \x ->
                      case properFraction x of {
                        (n, y) -> ((fromIntegral :: Int -> Int64) n, y :: Float) }
"truncate/Float->Int64"
    truncate = (fromIntegral :: Int -> Int64) . (truncate :: Float -> Int)
"floor/Float->Int64"
    floor    = (fromIntegral :: Int -> Int64) . (floor :: Float -> Int)
"ceiling/Float->Int64"
    ceiling  = (fromIntegral :: Int -> Int64) . (ceiling :: Float -> Int)
"round/Float->Int64"
    round    = (fromIntegral :: Int -> Int64) . (round  :: Float -> Int)
  #-}

{-# RULES
"properFraction/Double->(Int64,Double)"
    properFraction = \x ->
                      case properFraction x of {
                        (n, y) -> ((fromIntegral :: Int -> Int64) n, y :: Double) }
"truncate/Double->Int64"
    truncate = (fromIntegral :: Int -> Int64) . (truncate :: Double -> Int)
"floor/Double->Int64"
    floor    = (fromIntegral :: Int -> Int64) . (floor :: Double -> Int)
"ceiling/Double->Int64"
    ceiling  = (fromIntegral :: Int -> Int64) . (ceiling :: Double -> Int)
"round/Double->Int64"
    round    = (fromIntegral :: Int -> Int64) . (round  :: Double -> Int)
  #-}

uncheckedIShiftL64# :: Int# -> Int# -> Int#
uncheckedIShiftL64# :: Int# -> Int# -> Int#
uncheckedIShiftL64#  = Int# -> Int# -> Int#
uncheckedIShiftL#

uncheckedIShiftRA64# :: Int# -> Int# -> Int#
uncheckedIShiftRA64# :: Int# -> Int# -> Int#
uncheckedIShiftRA64# = Int# -> Int# -> Int#
uncheckedIShiftRA#
#endif

-- | @since 4.6.0.0
instance FiniteBits Int64 where
    finiteBitSize :: Int64 -> Int
finiteBitSize _ = 64
#if WORD_SIZE_IN_BITS < 64
    countLeadingZeros  (I64# x#) = I# (word2Int# (clz64# (int64ToWord64# x#)))
    countTrailingZeros (I64# x#) = I# (word2Int# (ctz64# (int64ToWord64# x#)))
#else
    countLeadingZeros :: Int64 -> Int
countLeadingZeros  (I64# x# :: Int#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz64# (Int# -> Word#
int2Word# Int#
x#)))
    countTrailingZeros :: Int64 -> Int
countTrailingZeros (I64# x# :: Int#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
ctz64# (Int# -> Word#
int2Word# Int#
x#)))
#endif

-- | @since 2.01
instance Real Int64 where
    toRational :: Int64 -> Rational
toRational x :: Int64
x = Int64 -> Integer
forall a. Integral a => a -> Integer
toInteger Int64
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% 1

-- | @since 2.01
instance Bounded Int64 where
    minBound :: Int64
minBound = -0x8000000000000000
    maxBound :: Int64
maxBound =  0x7FFFFFFFFFFFFFFF

-- | @since 2.01
instance Ix Int64 where
    range :: (Int64, Int64) -> [Int64]
range (m :: Int64
m,n :: Int64
n)         = [Int64
m..Int64
n]
    unsafeIndex :: (Int64, Int64) -> Int64 -> Int
unsafeIndex (m :: Int64
m,_) i :: Int64
i = Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
m
    inRange :: (Int64, Int64) -> Int64 -> Bool
inRange (m :: Int64
m,n :: Int64
n) i :: Int64
i     = Int64
m Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
i Bool -> Bool -> Bool
&& Int64
i Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
n

-------------------------------------------------------------------------------

{-# RULES
"fromIntegral/Natural->Int8"
    fromIntegral = (fromIntegral :: Int -> Int8)    . naturalToInt
"fromIntegral/Natural->Int16"
    fromIntegral = (fromIntegral :: Int -> Int16)   . naturalToInt
"fromIntegral/Natural->Int32"
    fromIntegral = (fromIntegral :: Int -> Int32)   . naturalToInt
  #-}

{-# RULES
"fromIntegral/Int8->Natural"
    fromIntegral = intToNatural  . (fromIntegral :: Int8  -> Int)
"fromIntegral/Int16->Natural"
    fromIntegral = intToNatural  . (fromIntegral :: Int16 -> Int)
"fromIntegral/Int32->Natural"
    fromIntegral = intToNatural  . (fromIntegral :: Int32 -> Int)
  #-}

#if WORD_SIZE_IN_BITS == 64
-- these RULES are valid for Word==Word64 & Int==Int64
{-# RULES
"fromIntegral/Natural->Int64"
    fromIntegral = (fromIntegral :: Int -> Int64) . naturalToInt
"fromIntegral/Int64->Natural"
    fromIntegral = intToNatural . (fromIntegral :: Int64 -> Int)
  #-}
#endif


{- Note [Order of tests]
~~~~~~~~~~~~~~~~~~~~~~~~~
(See Trac #3065, #5161.) Suppose we had a definition like:

    quot x y
     | y == 0                     = divZeroError
     | x == minBound && y == (-1) = overflowError
     | otherwise                  = x `primQuot` y

Note in particular that the
    x == minBound
test comes before the
    y == (-1)
test.

this expands to something like:

    case y of
    0 -> divZeroError
    _ -> case x of
         -9223372036854775808 ->
             case y of
             -1 -> overflowError
             _ -> x `primQuot` y
         _ -> x `primQuot` y

Now if we have the call (x `quot` 2), and quot gets inlined, then we get:

    case 2 of
    0 -> divZeroError
    _ -> case x of
         -9223372036854775808 ->
             case 2 of
             -1 -> overflowError
             _ -> x `primQuot` 2
         _ -> x `primQuot` 2

which simplifies to:

    case x of
    -9223372036854775808 -> x `primQuot` 2
    _                    -> x `primQuot` 2

Now we have a case with two identical branches, which would be
eliminated (assuming it doesn't affect strictness, which it doesn't in
this case), leaving the desired:

    x `primQuot` 2

except in the minBound branch we know what x is, and GHC cleverly does
the division at compile time, giving:

    case x of
    -9223372036854775808 -> -4611686018427387904
    _                    -> x `primQuot` 2

So instead we use a definition like:

    quot x y
     | y == 0                     = divZeroError
     | y == (-1) && x == minBound = overflowError
     | otherwise                  = x `primQuot` y

which gives us:

    case y of
    0 -> divZeroError
    -1 ->
        case x of
        -9223372036854775808 -> overflowError
        _ -> x `primQuot` y
    _ -> x `primQuot` y

for which our call (x `quot` 2) expands to:

    case 2 of
    0 -> divZeroError
    -1 ->
        case x of
        -9223372036854775808 -> overflowError
        _ -> x `primQuot` 2
    _ -> x `primQuot` 2

which simplifies to:

    x `primQuot` 2

as required.



But we now have the same problem with a constant numerator: the call
(2 `quot` y) expands to

    case y of
    0 -> divZeroError
    -1 ->
        case 2 of
        -9223372036854775808 -> overflowError
        _ -> 2 `primQuot` y
    _ -> 2 `primQuot` y

which simplifies to:

    case y of
    0 -> divZeroError
    -1 -> 2 `primQuot` y
    _ -> 2 `primQuot` y

which simplifies to:

    case y of
    0 -> divZeroError
    -1 -> -2
    _ -> 2 `primQuot` y


However, constant denominators are more common than constant numerators,
so the
    y == (-1) && x == minBound
order gives us better code in the common case.
-}