[project @ 2001-02-23 14:44:43 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / PrelInt.lhs
index 791a41c..04c49c8 100644 (file)
@@ -172,8 +172,7 @@ instance CReturnable Int8
 int8ToInt (I8# x)  = I# (i8ToInt# x)
 
 i8ToInt# :: Int# -> Int#
-i8ToInt# x = if x' <=# 0x7f# then x' else x' -# 0x100#
-   where x' = word2Int# (int2Word# x `and#` int2Word# 0xff#)
+i8ToInt# x = if x <=# 0x7f# then x else x -# 0x100#
 
 -- This doesn't perform any bounds checking on the value it is passed,
 -- nor its sign, i.e., show (intToInt8 511) => "-1"
@@ -189,12 +188,6 @@ instance Eq  Int8     where
 instance Ord Int8 where 
   compare (I8# x#) (I8# y#) = compareInt# (i8ToInt# x#) (i8ToInt# y#)
 
-compareInt# :: Int# -> Int# -> Ordering
-compareInt# x# y#
- | x# <#  y# = LT
- | x# ==# y# = EQ
- | otherwise = GT
-
 instance Num Int8 where
   (I8# x#) + (I8# y#) = I8# (intToInt8# (x# +# y#))
   (I8# x#) - (I8# y#) = I8# (intToInt8# (x# -# y#))
@@ -234,7 +227,6 @@ instance Integral Int8 where
 
     a@(I8# _) `quotRem` b@(I8# _) = (a `quotInt8` b, a `remInt8` b)
     toInteger i8  = toInteger (int8ToInt i8)
-    toInt     i8  = int8ToInt i8
 
 
 remInt8, quotInt8 :: Int8 -> Int8 -> Int8
@@ -257,7 +249,7 @@ instance Enum Int8 where
       | otherwise     = i-1
 
     toEnum x
-      | x >= toInt (minBound::Int8) && x <= toInt (maxBound::Int8) 
+      | x >= fromIntegral (minBound::Int8) && x <= fromIntegral (maxBound::Int8) 
       = intToInt8 x
       | otherwise
       = toEnumError "Int8" x (minBound::Int8,maxBound::Int8)
@@ -323,8 +315,8 @@ instance CReturnable Int16
 int16ToInt  (I16# x) = I# (i16ToInt# x)
 
 i16ToInt# :: Int# -> Int#
-i16ToInt# x = if x' <=# 0x7fff# then x' else x' -# 0x10000#
-   where x' = word2Int# (int2Word# x `and#` int2Word# 0xffff#)
+i16ToInt# x = if x <=# 0x7fff# then x else x -# 0x10000#
+       -- x's upper 16 bits should already be zero
 
 -- This doesn't perform any bounds checking on the value it is passed,
 -- nor its sign, i.e., show (intToInt8 131071) => "-1"
@@ -378,12 +370,10 @@ instance Integral Int16 where
 
     a@(I16# _) `quotRem` b@(I16# _) = (a `quotInt16` b, a `remInt16` b)
     toInteger i16  = toInteger (int16ToInt i16)
-    toInt     i16  = int16ToInt i16
 
 remInt16, quotInt16 :: Int16 -> Int16 -> Int16
 remInt16  (I16# x) (I16# y) = I16# (intToInt16# ((i16ToInt# x) `remInt#` (i16ToInt# y)))
 quotInt16 (I16# x) (I16# y) = I16# (intToInt16# ((i16ToInt# x) `quotInt#` (i16ToInt# y)))
-
 instance Ix Int16 where
     range (m,n)          = [m..n]
     index b@(m,_) i
@@ -401,7 +391,7 @@ instance Enum Int16 where
       | otherwise     = i-1
 
     toEnum x
-      | x >= toInt (minBound::Int16) && x <= toInt (maxBound::Int16) 
+      | x >= fromIntegral (minBound::Int16) && x <= fromIntegral (maxBound::Int16) 
       = intToInt16 x
       | otherwise
       = toEnumError "Int16" x (minBound::Int16, maxBound::Int16)
@@ -529,7 +519,6 @@ instance Integral Int32 where
 
     a@(I32# _) `quotRem` b@(I32# _) = (a `quotInt32` b, a `remInt32` b)
     toInteger i32  = toInteger (int32ToInt i32)
-    toInt     i32  = int32ToInt i32
 
 remInt32, quotInt32 :: Int32 -> Int32 -> Int32
 remInt32  (I32# x) (I32# y) = I32# (intToInt32# ((i32ToInt# x) `remInt#`  (i32ToInt# y)))
@@ -554,7 +543,7 @@ instance Enum Int32 where
     toEnum x
         -- with Int having the same range as Int32, the following test
        -- shouldn't fail. However, having it here 
-      | x >= toInt (minBound::Int32) && x <= toInt (maxBound::Int32) 
+      | x >= fromIntegral (minBound::Int32) && x <= fromIntegral (maxBound::Int32) 
       = intToInt32 x
       | otherwise
       = toEnumError "Int32" x (minBound::Int32, maxBound::Int32)
@@ -663,7 +652,6 @@ instance Integral Int64 where
 
     a@(I64# _) `quotRem` b@(I64# _) = (a `quotInt64` b, a `remInt64` b)
     toInteger (I64# i#) = toInteger (I# i#)
-    toInt     (I64# i#) = I# i#
 
 remInt64  (I64# x) (I64# y) = I64# (x `remInt#` y)
 quotInt64 (I64# x) (I64# y) = I64# (x `quotInt#` y)
@@ -743,7 +731,6 @@ instance Integral Int64 where
 
     a@(I64# _) `quotRem` b@(I64# _) = (a `quotInt64` b, a `remInt64` b)
     toInteger i         = int64ToInteger i
-    toInt     i         = int64ToInt i
 
 remInt64, quotInt64 :: Int64 -> Int64 -> Int64
 remInt64  (I64# x) (I64# y) = I64# (x `remInt64#` y)