1ff37bd51cb3d8f387620d031c13c47cc2bb7fd8
[packages/base.git] / Data / Int.hs
1 {-# LANGUAGE Trustworthy #-}
2 {-# LANGUAGE CPP, NoImplicitPrelude #-}
3
4 -----------------------------------------------------------------------------
5 -- |
6 -- Module : Data.Int
7 -- Copyright : (c) The University of Glasgow 2001
8 -- License : BSD-style (see the file libraries/base/LICENSE)
9 --
10 -- Maintainer : libraries@haskell.org
11 -- Stability : experimental
12 -- Portability : portable
13 --
14 -- Signed integer types
15 --
16 -----------------------------------------------------------------------------
17
18 module Data.Int
19 (
20 -- * Signed integer types
21 Int,
22 Int8, Int16, Int32, Int64,
23
24 -- * Notes
25
26 -- $notes
27 ) where
28
29 #ifdef __GLASGOW_HASKELL__
30 import GHC.Base ( Int )
31 import GHC.Int ( Int8, Int16, Int32, Int64 )
32 #endif
33
34 #ifdef __HUGS__
35 import Hugs.Int ( Int8, Int16, Int32, Int64 )
36 #endif
37
38 #ifdef __NHC__
39 import Prelude
40 import Prelude (Int)
41 import NHC.FFI (Int8, Int16, Int32, Int64)
42 import NHC.SizedTypes (Int8, Int16, Int32, Int64) -- instances of Bits
43 #endif
44
45 {- $notes
46
47 * All arithmetic is performed modulo 2^n, where @n@ is the number of
48 bits in the type.
49
50 * For coercing between any two integer types, use 'Prelude.fromIntegral',
51 which is specialized for all the common cases so should be fast
52 enough. Coercing word types (see "Data.Word") to and from integer
53 types preserves representation, not sign.
54
55 * The rules that hold for 'Prelude.Enum' instances over a
56 bounded type such as 'Int' (see the section of the
57 Haskell report dealing with arithmetic sequences) also hold for the
58 'Prelude.Enum' instances over the various
59 'Int' types defined here.
60
61 * Right and left shifts by amounts greater than or equal to the width
62 of the type result in either zero or -1, depending on the sign of
63 the value being shifted. This is contrary to the behaviour in C,
64 which is undefined; a common interpretation is to truncate the shift
65 count to the width of the type, for example @1 \<\< 32
66 == 1@ in some C implementations.
67 -}