5 This library provides unsigned integers of various sizes.
6 The types supported are as follows:
9 <!-- ToDo: figure out why the ldoc DTD doesn't allow hline's - it looks as if -->
12 type | number of bits @
21 For each type <it/W/ above, we provide the following functions and
22 instances. The type <it/I/ refers to the signed integer type of the
26 data W -- Unsigned Ints
41 word8ToWord16 :: Word8 -> Word16
42 word8ToWord32 :: Word8 -> Word32
43 word8ToWord64 :: Word8 -> Word64
45 word16ToWord8 :: Word16 -> Word8
46 word16ToWord32 :: Word16 -> Word32
47 word16ToWord64 :: Word16 -> Word64
49 word32ToWord8 :: Word32 -> Word8
50 word32ToWord16 :: Word32 -> Word16
51 word32ToWord64 :: Word32 -> Word64
53 word64ToWord8 :: Word64 -> Word8
54 word64ToWord16 :: Word64 -> Word16
55 word64ToWord32 :: Word64 -> Word32
57 word8ToInt :: Word8 -> Int
58 word16ToInt :: Word16 -> Int
59 word32ToInt :: Word32 -> Int
60 word64ToInt :: Word64 -> Int
62 intToWord8 :: Int -> Word8
63 intToWord16 :: Int -> Word16
64 intToWord32 :: Int -> Word32
65 intToWord64 :: Int -> Word64
67 word64ToInteger :: Word64 -> Integer
68 integerToWord64 :: Integer -> Word64
75 All arithmetic is performed modulo 2^n
77 One non-obvious consequence of this is that <tt/negate/
78 should <em/not/ raise an error on negative arguments.
81 The coercion <tt/wToI/ converts an unsigned n-bit value to the
82 signed n-bit value with the same representation. For example,
83 <tt/word8ToInt8 0xff = -1/.
84 Likewise, <tt/iToW/ converts signed n-bit values to the
85 corresponding unsigned n-bit value.
88 Use <tt/Prelude.fromIntegral :: (Integral a, Num b) => a -> b/ to
89 coerce between different sizes or to preserve sign when converting
90 between values of the same size.
93 It would be very natural to add a type a type <tt/Natural/ providing
94 an unbounded size unsigned integer --- just as <tt/Integer/ provides
95 unbounded size signed integers. We do not do that yet since there is
96 no demand for it. Doing so would require <tt/Bits.bitSize/ to return
100 The rules that hold for <tt/Enum/ instances over a bounded type
101 such as <tt/Int/ (see the section of the Haskell report dealing
102 with arithmetic sequences) also hold for the <tt/Enum/ instances
103 over the various <tt/Word/ types defined here.
107 <bf/Implementation notes:/
110 <item> Hugs only provides <tt/Eq/, <tt/Ord/, <tt/Read/ and <tt/Show/
111 instances for <tt/Word64/ at the moment.