Skip to content
Snippets Groups Projects
Commit 38d3857b authored by Simon Marlow's avatar Simon Marlow
Browse files

[project @ 1997-11-20 16:45:38 by simonm]

* fix minBound::Int32 in view of the fact that minBound::Int is wrong.
* fix shift direction (it was reversed)
* fix complement to be a 1's complement instead of 2's complement
parent 449e1794
No related merge requests found
......@@ -244,9 +244,11 @@ instance Num Int32 where
fromInteger = to . fromInteger
fromInt = to
instance Bounded Int32 where
minBound = to minBound
maxBound = to maxBound
-- ToDo: remove LitLit when minBound::Int is fixed (currently it's one
-- too high, and doesn't allow the correct minBound to be defined here).
instance Bounded Int32 where
minBound = I32 ``0x80000000''
maxBound = I32 0x7fffffff
instance Real Int32 where
toRational x = toInteger x % 1
......@@ -284,12 +286,12 @@ instance Bits Int32 where
x .&. y = to (binop (wordop and#) x y)
x .|. y = to (binop (wordop or# ) x y)
x `xor` y = to (binop (wordop xor#) x y)
complement x = (x `xor` maxBound) + 1
complement x = x `xor` -1
shift (I32 (I# x)) i@(I# i#)
| i > 0 = I32 (I# (iShiftRL# x i#))
| otherwise = I32 (I# (iShiftL# x i#))
| i > 0 = I32 (I# (iShiftL# x i#))
| otherwise = I32 (I# (iShiftRA# x i#))
-- rotate
bit i = 1 `shift` -i
bit i = 1 `shift` i
setBit x i = x .|. bit i
clearBit x i = x .&. complement (bit i)
complementBit x i = x `xor` bit i
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment