summaryrefslogtreecommitdiff
path: root/testsuite/tests/lib/integer/integerConversions.hs
blob: 9b10bbdff27ade72cdfac0a1b9526d1f6a7a9bb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

module Main (main) where

import Data.Int
import Data.Word

around :: Integer -> [Integer]
around i = [i - 2, i - 1, i, i + 1, i + 2]

dump :: Show a => String -> [a] -> IO ()
dump s xs = do putStrLn "===================================="
               putStrLn s
               mapM_ print xs

main :: IO ()
main = do let xs :: [[Integer]]
              xs = [around 0,
                    around (2^30),
                    around (2^31),
                    around (2^32),
                    around (2^33),
                    around (2^34),
                    around (2^62),
                    around (2^63),
                    around (2^64),
                    around (2^65),
                    around (2^66),
                    around (-(2^30)),
                    around (-(2^31)),
                    around (-(2^32)),
                    around (-(2^33)),
                    around (-(2^34)),
                    around (-(2^62)),
                    around (-(2^63)),
                    around (-(2^64)),
                    around (-(2^65)),
                    around (-(2^66))]
              xsInt :: [[Int]]
              xsInt = map (map fromInteger) xs
              xsIntInteger :: [[Integer]]
              xsIntInteger = map (map toInteger) xsInt
              xsInt32 :: [[Int32]]
              xsInt32 = map (map fromInteger) xs
              xsInt32Integer :: [[Integer]]
              xsInt32Integer = map (map toInteger) xsInt32
              xsInt64 :: [[Int64]]
              xsInt64 = map (map fromInteger) xs
              xsInt64Integer :: [[Integer]]
              xsInt64Integer = map (map toInteger) xsInt64
              xsWord :: [[Word]]
              xsWord = map (map fromInteger) xs
              xsWordInteger :: [[Integer]]
              xsWordInteger = map (map toInteger) xsWord
              xsWord32 :: [[Word32]]
              xsWord32 = map (map fromInteger) xs
              xsWord32Integer :: [[Integer]]
              xsWord32Integer = map (map toInteger) xsWord32
              xsWord64 :: [[Word64]]
              xsWord64 = map (map fromInteger) xs
              xsWord64Integer :: [[Integer]]
              xsWord64Integer = map (map toInteger) xsWord64
          dump "xs" xs
          dump "xsInt" xsInt
          dump "xsIntInteger" xsIntInteger
          dump "xsInt32" xsInt32
          dump "xsInt32Integer" xsInt32Integer
          dump "xsInt64" xsInt64
          dump "xsInt64Integer" xsInt64Integer
          dump "xsWord" xsWord
          dump "xsWordInteger" xsWordInteger
          dump "xsWord32" xsWord32
          dump "xsWord32Integer" xsWord32Integer
          dump "xsWord64" xsWord64
          dump "xsWord64Integer" xsWord64Integer

test :: String -> Integer -> Integer -> IO ()
test what want got
 | want == got = return ()
 | otherwise   = print (what, want, got)