[project @ 1998-01-07 18:12:40 by simonm]
[ghc-hetmet.git] / ghc / tests / numeric / should_run / arith004.hs
1 --!!! test quot/rem/div/mod functions on Ints and Integers
2 --
3 main
4   = putStr
5        (-- w/ Ints and Integers
6         show (unzipWith div ints_list)
7         ++ "\n"
8         ++ show (unzipWith div integers_list)
9         ++ "\n"
10         ++ show (unzipWith rem ints_list)
11         ++ "\n"
12         ++ show (unzipWith rem integers_list)
13         ++ "\n"
14         ++ show (unzipWith quot ints_list)
15         ++ "\n"
16         ++ show (unzipWith quot integers_list)
17         ++ "\n"
18         ++ show (unzipWith mod ints_list)
19         ++ "\n"
20         ++ show (unzipWith mod integers_list)
21         ++ "\n"
22         ++ show (unzipWith law1 ints_list)
23         ++ "\n"
24         ++ show (unzipWith law1 integers_list)
25         ++ "\n"
26         ++ show (unzipWith law2 ints_list)
27         ++ "\n"
28         ++ show (unzipWith law2 integers_list)
29         ++ "\n"
30         )
31   where
32     ints_list :: [(Int, Int)]
33     integers_list :: [(Integer, Integer)]
34
35     ints_list = [
36         (0, 4),
37         (0, -8),
38         (7, 3),
39         (13, 4),
40         (13, -4),
41         (-13, 4),
42         (-13, -4),
43         (12345678, 10000),
44         (12345678, -10000),
45         (-12345678, 10000),
46         (-12345678, -10000),
47         (123456,10000),
48         (1234567,20000),
49         (12345678,-10000),
50         (123456789,10000),
51         (1234567890,-10000),
52         (-12345,10000),
53         (-123456789,-10000)
54         ]
55
56     integers_list = [
57         (0, 4),
58         (0, -8),
59         (7, 3),
60         (13, 4),
61         (13, -4),
62         (-13, 4),
63         (-13, -4),
64         (12345678, 10000),
65         (12345678, -10000),
66         (-12345678, 10000),
67         (-12345678, -10000),
68         (123456,10000),
69         (1234567,20000),
70         (12345678,-10000),
71         (123456789,10000),
72         (1234567890,-10000),
73         (-12345,10000),
74         (-123456789,-10000),
75         (12345678900,500000000),
76         (1234000000000000000000005678900,5001111111111111000000)
77         ]
78
79 unzipWith :: (a -> b -> c) -> [(a,b)] -> [c]
80 unzipWith f []         = []
81 unzipWith f ((x,y):zs) = f x y : unzipWith f zs
82
83 law1, law2 :: Integral a => a -> a -> Bool
84
85 law1 x y = (x `quot` y)*y + (x `rem` y) == x
86 law2 x y = (x `div`  y)*y + (x `mod` y) == x