instance Integral Int8 where
quot x@(I8# x#) y@(I8# y#)
- | y /= 0 = I8# (narrow8Int# (x# `quotInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I8# (narrow8Int# (x# `quotInt#` y#))
rem x@(I8# x#) y@(I8# y#)
- | y /= 0 = I8# (narrow8Int# (x# `remInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I8# (narrow8Int# (x# `remInt#` y#))
div x@(I8# x#) y@(I8# y#)
- | y /= 0 = I8# (narrow8Int# (x# `divInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I8# (narrow8Int# (x# `divInt#` y#))
mod x@(I8# x#) y@(I8# y#)
- | y /= 0 = I8# (narrow8Int# (x# `modInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I8# (narrow8Int# (x# `modInt#` y#))
quotRem x@(I8# x#) y@(I8# y#)
- | y /= 0 = (I8# (narrow8Int# (x# `quotInt#` y#)),
- I8# (narrow8Int# (x# `remInt#` y#)))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I8# (narrow8Int# (x# `quotInt#` y#)),
+ I8# (narrow8Int# (x# `remInt#` y#)))
divMod x@(I8# x#) y@(I8# y#)
- | y /= 0 = (I8# (narrow8Int# (x# `divInt#` y#)),
- I8# (narrow8Int# (x# `modInt#` y#)))
- | otherwise = divZeroError
- toInteger (I8# x#) = S# x#
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I8# (narrow8Int# (x# `divInt#` y#)),
+ I8# (narrow8Int# (x# `modInt#` y#)))
+ toInteger (I8# x#) = S# x#
instance Bounded Int8 where
minBound = -0x80
instance Integral Int16 where
quot x@(I16# x#) y@(I16# y#)
- | y /= 0 = I16# (narrow16Int# (x# `quotInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I16# (narrow16Int# (x# `quotInt#` y#))
rem x@(I16# x#) y@(I16# y#)
- | y /= 0 = I16# (narrow16Int# (x# `remInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I16# (narrow16Int# (x# `remInt#` y#))
div x@(I16# x#) y@(I16# y#)
- | y /= 0 = I16# (narrow16Int# (x# `divInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I16# (narrow16Int# (x# `divInt#` y#))
mod x@(I16# x#) y@(I16# y#)
- | y /= 0 = I16# (narrow16Int# (x# `modInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I16# (narrow16Int# (x# `modInt#` y#))
quotRem x@(I16# x#) y@(I16# y#)
- | y /= 0 = (I16# (narrow16Int# (x# `quotInt#` y#)),
- I16# (narrow16Int# (x# `remInt#` y#)))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I16# (narrow16Int# (x# `quotInt#` y#)),
+ I16# (narrow16Int# (x# `remInt#` y#)))
divMod x@(I16# x#) y@(I16# y#)
- | y /= 0 = (I16# (narrow16Int# (x# `divInt#` y#)),
- I16# (narrow16Int# (x# `modInt#` y#)))
- | otherwise = divZeroError
- toInteger (I16# x#) = S# x#
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I16# (narrow16Int# (x# `divInt#` y#)),
+ I16# (narrow16Int# (x# `modInt#` y#)))
+ toInteger (I16# x#) = S# x#
instance Bounded Int16 where
minBound = -0x8000
instance Integral Int32 where
quot x@(I32# x#) y@(I32# y#)
- | y /= 0 = I32# (x# `quotInt32#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I32# (x# `quotInt32#` y#)
rem x@(I32# x#) y@(I32# y#)
- | y /= 0 = I32# (x# `remInt32#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I32# (x# `remInt32#` y#)
div x@(I32# x#) y@(I32# y#)
- | y /= 0 = I32# (x# `divInt32#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I32# (x# `divInt32#` y#)
mod x@(I32# x#) y@(I32# y#)
- | y /= 0 = I32# (x# `modInt32#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I32# (x# `modInt32#` y#)
quotRem x@(I32# x#) y@(I32# y#)
- | y /= 0 = (I32# (x# `quotInt32#` y#), I32# (x# `remInt32#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I32# (x# `quotInt32#` y#),
+ I32# (x# `remInt32#` y#))
divMod x@(I32# x#) y@(I32# y#)
- | y /= 0 = (I32# (x# `divInt32#` y#), I32# (x# `modInt32#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I32# (x# `divInt32#` y#),
+ I32# (x# `modInt32#` y#))
toInteger x@(I32# x#)
| x >= fromIntegral (minBound::Int) && x <= fromIntegral (maxBound::Int)
= S# (int32ToInt# x#)
instance Integral Int32 where
quot x@(I32# x#) y@(I32# y#)
- | y /= 0 = I32# (narrow32Int# (x# `quotInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I32# (narrow32Int# (x# `quotInt#` y#))
rem x@(I32# x#) y@(I32# y#)
- | y /= 0 = I32# (narrow32Int# (x# `remInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I32# (narrow32Int# (x# `remInt#` y#))
div x@(I32# x#) y@(I32# y#)
- | y /= 0 = I32# (narrow32Int# (x# `divInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I32# (narrow32Int# (x# `divInt#` y#))
mod x@(I32# x#) y@(I32# y#)
- | y /= 0 = I32# (narrow32Int# (x# `modInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I32# (narrow32Int# (x# `modInt#` y#))
quotRem x@(I32# x#) y@(I32# y#)
- | y /= 0 = (I32# (narrow32Int# (x# `quotInt#` y#)),
- I32# (narrow32Int# (x# `remInt#` y#)))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I32# (narrow32Int# (x# `quotInt#` y#)),
+ I32# (narrow32Int# (x# `remInt#` y#)))
divMod x@(I32# x#) y@(I32# y#)
- | y /= 0 = (I32# (narrow32Int# (x# `divInt#` y#)),
- I32# (narrow32Int# (x# `modInt#` y#)))
- | otherwise = divZeroError
- toInteger (I32# x#) = S# x#
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I32# (narrow32Int# (x# `divInt#` y#)),
+ I32# (narrow32Int# (x# `modInt#` y#)))
+ toInteger (I32# x#) = S# x#
instance Read Int32 where
readsPrec p s = [(fromIntegral (x::Int), r) | (x, r) <- readsPrec p s]
instance Integral Int64 where
quot x@(I64# x#) y@(I64# y#)
- | y /= 0 = I64# (x# `quotInt64#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I64# (x# `quotInt64#` y#)
rem x@(I64# x#) y@(I64# y#)
- | y /= 0 = I64# (x# `remInt64#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I64# (x# `remInt64#` y#)
div x@(I64# x#) y@(I64# y#)
- | y /= 0 = I64# (x# `divInt64#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I64# (x# `divInt64#` y#)
mod x@(I64# x#) y@(I64# y#)
- | y /= 0 = I64# (x# `modInt64#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I64# (x# `modInt64#` y#)
quotRem x@(I64# x#) y@(I64# y#)
- | y /= 0 = (I64# (x# `quotInt64#` y#), I64# (x# `remInt64#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I64# (x# `quotInt64#` y#),
+ I64# (x# `remInt64#` y#))
divMod x@(I64# x#) y@(I64# y#)
- | y /= 0 = (I64# (x# `divInt64#` y#), I64# (x# `modInt64#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I64# (x# `divInt64#` y#),
+ I64# (x# `modInt64#` y#))
toInteger x@(I64# x#)
- | x >= fromIntegral (minBound::Int) && x <= fromIntegral (maxBound::Int)
- = S# (int64ToInt# x#)
- | otherwise = case int64ToInteger# x# of (# s, d #) -> J# s d
+ | x >= fromIntegral (minBound::Int) &&
+ x <= fromIntegral (maxBound::Int)
+ = S# (int64ToInt# x#)
+ | otherwise = case int64ToInteger# x# of
+ (# s, d #) -> J# s d
divInt64#, modInt64# :: Int64# -> Int64# -> Int64#
| otherwise = a `uncheckedIShiftRA64#` b
-foreign import ccall unsafe "stg_eqInt64" eqInt64# :: Int64# -> Int64# -> Bool
-foreign import ccall unsafe "stg_neInt64" neInt64# :: Int64# -> Int64# -> Bool
-foreign import ccall unsafe "stg_ltInt64" ltInt64# :: Int64# -> Int64# -> Bool
-foreign import ccall unsafe "stg_leInt64" leInt64# :: Int64# -> Int64# -> Bool
-foreign import ccall unsafe "stg_gtInt64" gtInt64# :: Int64# -> Int64# -> Bool
-foreign import ccall unsafe "stg_geInt64" geInt64# :: Int64# -> Int64# -> Bool
-foreign import ccall unsafe "stg_plusInt64" plusInt64# :: Int64# -> Int64# -> Int64#
-foreign import ccall unsafe "stg_minusInt64" minusInt64# :: Int64# -> Int64# -> Int64#
-foreign import ccall unsafe "stg_timesInt64" timesInt64# :: Int64# -> Int64# -> Int64#
-foreign import ccall unsafe "stg_negateInt64" negateInt64# :: Int64# -> Int64#
-foreign import ccall unsafe "stg_quotInt64" quotInt64# :: Int64# -> Int64# -> Int64#
-foreign import ccall unsafe "stg_remInt64" remInt64# :: Int64# -> Int64# -> Int64#
-foreign import ccall unsafe "stg_intToInt64" intToInt64# :: Int# -> Int64#
-foreign import ccall unsafe "stg_int64ToInt" int64ToInt# :: Int64# -> Int#
-foreign import ccall unsafe "stg_wordToWord64" wordToWord64# :: Word# -> Word64#
-foreign import ccall unsafe "stg_int64ToWord64" int64ToWord64# :: Int64# -> Word64#
-foreign import ccall unsafe "stg_word64ToInt64" word64ToInt64# :: Word64# -> Int64#
-foreign import ccall unsafe "stg_and64" and64# :: Word64# -> Word64# -> Word64#
-foreign import ccall unsafe "stg_or64" or64# :: Word64# -> Word64# -> Word64#
-foreign import ccall unsafe "stg_xor64" xor64# :: Word64# -> Word64# -> Word64#
-foreign import ccall unsafe "stg_not64" not64# :: Word64# -> Word64#
-foreign import ccall unsafe "stg_uncheckedShiftL64" uncheckedShiftL64# :: Word64# -> Int# -> Word64#
-foreign import ccall unsafe "stg_uncheckedShiftRL64" uncheckedShiftRL64# :: Word64# -> Int# -> Word64#
-foreign import ccall unsafe "stg_uncheckedIShiftL64" uncheckedIShiftL64# :: Int64# -> Int# -> Int64#
-foreign import ccall unsafe "stg_uncheckedIShiftRA64" uncheckedIShiftRA64# :: Int64# -> Int# -> Int64#
-
-foreign import ccall unsafe "stg_integerToInt64" integerToInt64# :: Int# -> ByteArray# -> Int64#
+foreign import ccall unsafe "hs_eqInt64" eqInt64# :: Int64# -> Int64# -> Bool
+foreign import ccall unsafe "hs_neInt64" neInt64# :: Int64# -> Int64# -> Bool
+foreign import ccall unsafe "hs_ltInt64" ltInt64# :: Int64# -> Int64# -> Bool
+foreign import ccall unsafe "hs_leInt64" leInt64# :: Int64# -> Int64# -> Bool
+foreign import ccall unsafe "hs_gtInt64" gtInt64# :: Int64# -> Int64# -> Bool
+foreign import ccall unsafe "hs_geInt64" geInt64# :: Int64# -> Int64# -> Bool
+foreign import ccall unsafe "hs_plusInt64" plusInt64# :: Int64# -> Int64# -> Int64#
+foreign import ccall unsafe "hs_minusInt64" minusInt64# :: Int64# -> Int64# -> Int64#
+foreign import ccall unsafe "hs_timesInt64" timesInt64# :: Int64# -> Int64# -> Int64#
+foreign import ccall unsafe "hs_negateInt64" negateInt64# :: Int64# -> Int64#
+foreign import ccall unsafe "hs_quotInt64" quotInt64# :: Int64# -> Int64# -> Int64#
+foreign import ccall unsafe "hs_remInt64" remInt64# :: Int64# -> Int64# -> Int64#
+foreign import ccall unsafe "hs_intToInt64" intToInt64# :: Int# -> Int64#
+foreign import ccall unsafe "hs_int64ToInt" int64ToInt# :: Int64# -> Int#
+foreign import ccall unsafe "hs_wordToWord64" wordToWord64# :: Word# -> Word64#
+foreign import ccall unsafe "hs_int64ToWord64" int64ToWord64# :: Int64# -> Word64#
+foreign import ccall unsafe "hs_word64ToInt64" word64ToInt64# :: Word64# -> Int64#
+foreign import ccall unsafe "hs_and64" and64# :: Word64# -> Word64# -> Word64#
+foreign import ccall unsafe "hs_or64" or64# :: Word64# -> Word64# -> Word64#
+foreign import ccall unsafe "hs_xor64" xor64# :: Word64# -> Word64# -> Word64#
+foreign import ccall unsafe "hs_not64" not64# :: Word64# -> Word64#
+foreign import ccall unsafe "hs_uncheckedShiftL64" uncheckedShiftL64# :: Word64# -> Int# -> Word64#
+foreign import ccall unsafe "hs_uncheckedShiftRL64" uncheckedShiftRL64# :: Word64# -> Int# -> Word64#
+foreign import ccall unsafe "hs_uncheckedIShiftL64" uncheckedIShiftL64# :: Int64# -> Int# -> Int64#
+foreign import ccall unsafe "hs_uncheckedIShiftRA64" uncheckedIShiftRA64# :: Int64# -> Int# -> Int64#
+
+foreign import ccall unsafe "hs_integerToInt64" integerToInt64# :: Int# -> ByteArray# -> Int64#
{-# RULES
"fromIntegral/Int->Int64" fromIntegral = \(I# x#) -> I64# (intToInt64# x#)
instance Integral Int64 where
quot x@(I64# x#) y@(I64# y#)
- | y /= 0 = I64# (x# `quotInt#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I64# (x# `quotInt#` y#)
rem x@(I64# x#) y@(I64# y#)
- | y /= 0 = I64# (x# `remInt#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I64# (x# `remInt#` y#)
div x@(I64# x#) y@(I64# y#)
- | y /= 0 = I64# (x# `divInt#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I64# (x# `divInt#` y#)
mod x@(I64# x#) y@(I64# y#)
- | y /= 0 = I64# (x# `modInt#` y#)
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = I64# (x# `modInt#` y#)
quotRem x@(I64# x#) y@(I64# y#)
- | y /= 0 = (I64# (x# `quotInt#` y#), I64# (x# `remInt#` y#))
- | otherwise = divZeroError
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I64# (x# `quotInt#` y#), I64# (x# `remInt#` y#))
divMod x@(I64# x#) y@(I64# y#)
- | y /= 0 = (I64# (x# `divInt#` y#), I64# (x# `modInt#` y#))
- | otherwise = divZeroError
- toInteger (I64# x#) = S# x#
+ | y == 0 = divZeroError
+ | x == minBound && y == (-1) = overflowError
+ | otherwise = (I64# (x# `divInt#` y#), I64# (x# `modInt#` y#))
+ toInteger (I64# x#) = S# x#
instance Read Int64 where
readsPrec p s = [(fromIntegral (x::Int), r) | (x, r) <- readsPrec p s]