- toRational x = toInteger x % 1
-
-#if WORD_SIZE_IN_BYTES == 8
-
-instance Bits Word64 where
- (W64# x) .&. (W64# y) = W64# (x `and#` y)
- (W64# x) .|. (W64# y) = W64# (x `or#` y)
- (W64# x) `xor` (W64# y) = W64# (x `xor#` y)
- complement (W64# x) = W64# (x `xor#` (case (maxBound::Word64) of W64# x# -> x#))
- shift (W64# x#) i@(I# i#)
- | i > 0 = W64# (shiftL# x# i#)
- | otherwise = W64# (shiftRL# x# (negateInt# i#))
-
- w@(W64# x) `rotate` (I# i)
- | i ==# 0# = w
- | i ># 0# = W64# (shiftL# x i') `or#`
- (shiftRL# (x `and#`
- (int2Word# (word2Int# maxBound# -# pow2# i2 +# 1#)))
- i2))
- | otherwise = rotate w (I# (64# +# i))
- where
- i' = word2Int# (int2Word# i `and#` int2Word# 63#)
- i2 = 64# -# i'
- (W64# maxBound#) = maxBound
-
- bit (I# i#)
- | i# >=# 0# && i# <=# 63# = W64# (shiftL# (int2Word# 1#) i#)
- | otherwise = 0 -- We'll be overbearing, for now..
-
- testBit (W64# x#) (I# i#)
- | i# <# 64# && i# >=# 0# = (word2Int# (x# `and#` (shiftL# (int2Word# 1#) i#))) /=# 0#
- | otherwise = False -- for now, this is really an error.
-
- bitSize _ = 64
- isSigned _ = False
-
-#else /* WORD_SIZE_IN_BYTES < 8 */
-
-instance Bits Word64 where
- (W64# x) .&. (W64# y) = W64# (x `and64#` y)
- (W64# x) .|. (W64# y) = W64# (x `or64#` y)
- (W64# x) `xor` (W64# y) = W64# (x `xor64#` y)
- complement (W64# x) = W64# (x `xor64#` (case (maxBound::Word64) of W64# x# -> x#))
- shift (W64# x#) i@(I# i#)
- | i > 0 = W64# (shiftL64# x# i#)
- | otherwise = W64# (shiftRL64# x# (negateInt# i#))
-
- w@(W64# x) `rotate` (I# i)
- | i ==# 0# = w
- | i ># 0# = W64# ((shiftL64# x i') `or64#`
- (shiftRL64# (x `and64#`
- (int64ToWord64# ((word64ToInt64# maxBound#) `minusInt64#`
- (pow2_64# i2 `plusInt64#` (intToInt64# 1#))))))
- i2)
- | otherwise = rotate w (I# (64# +# i))
- where
- i' = word2Int# (int2Word# i `and#` int2Word# 63#)
- i2 = 64# -# i'
- (W64# maxBound#) = maxBound
-
- bit (I# i#)
- | i# >=# 0# && i# <=# 63# = W64# (shiftL64# (wordToWord64# (int2Word# 1#)) i#)
- | otherwise = 0 -- We'll be overbearing, for now..
-
- testBit (W64# x#) (I# i#)
- | i# <# 64# && i# >=# 0# = (word2Int# (word64ToWord# (x# `and64#` (shiftL64# (wordToWord64# (int2Word# 1#)) i#)))) /=# 0#
- | otherwise = False -- for now, this is really an error.
-
- bitSize _ = 64
- isSigned _ = False
-
-foreign import "stg_not64" unsafe not64# :: Word64# -> Word64#
-foreign import "stg_xor64" unsafe xor64# :: Word64# -> Word64# -> Word64#
-foreign import "stg_or64" unsafe or64# :: Word64# -> Word64# -> Word64#
-foreign import "stg_and64" unsafe and64# :: Word64# -> Word64# -> Word64#
-foreign import "stg_shiftRL64" unsafe shiftRL64# :: Word64# -> Int# -> Word64#
-foreign import "stg_shiftL64" unsafe shiftL64# :: Word64# -> Int# -> Word64#
-
-#endif /* WORD_SIZE_IN_BYTES < 8 */
-\end{code}
-
-Misc utils.
-
-\begin{code}
-signumReal :: (Ord a, Num a) => a -> a
-signumReal x | x == 0 = 0
- | x > 0 = 1
- | otherwise = -1
-\end{code}
-
-Utils for generating friendly error messages.
-
-\begin{code}
-toEnumError :: (Show a,Show b) => String -> a -> (b,b) -> c
-toEnumError inst_ty tag bnds
- = error ("Enum.toEnum{" ++ inst_ty ++ "}: tag " ++
- (showParen True (showsPrec 0 tag) $
- " is outside of bounds " ++
- show bnds))
-
-fromEnumError :: (Show a,Show b) => String -> a -> b
-fromEnumError inst_ty tag
- = error ("Enum.fromEnum{" ++ inst_ty ++ "}: value " ++
- (showParen True (showsPrec 0 tag) $
- " is outside of Int's bounds " ++
- show (minBound::Int,maxBound::Int)))