179d7b33dc9556089e1a270308f420531b4b1807
[ghc.git] / testsuite / tests / numeric / should_run / arith005.hs
1 -- !!! test RealFrac ops (ceiling/floor/etc.) on Floats/Doubles
2 --
3 main =
4 putStr $
5 unlines
6 [ -- just for fun, we show the floats to
7 -- exercise the code responsible.
8 'A' : show (float_list :: [Float])
9 , 'B' : show (double_list :: [Double])
10 -- {Float,Double} inputs, {Int,Integer} outputs
11 , 'C' : show ((map ceiling small_float_list) :: [Int])
12 , 'D' : show ((map ceiling float_list) :: [Integer])
13 , 'E' : show ((map ceiling small_double_list) :: [Int])
14 , 'F' : show ((map ceiling double_list) :: [Integer])
15 , 'G' : show ((map floor small_float_list) :: [Int])
16 , 'H' : show ((map floor float_list) :: [Integer])
17 , 'I' : show ((map floor small_double_list) :: [Int])
18 , 'J' : show ((map floor double_list) :: [Integer])
19 , 'K' : show ((map truncate small_float_list) :: [Int])
20 , 'L' : show ((map truncate float_list) :: [Integer])
21 , 'M' : show ((map truncate small_double_list) :: [Int])
22 , 'N' : show ((map truncate double_list) :: [Integer])
23 , 'n' : show ((map round small_float_list) :: [Int])
24 , 'O' : show ((map round float_list) :: [Integer])
25 , 'P' : show ((map round small_double_list) :: [Int])
26 , 'Q' : show ((map round double_list) :: [Integer])
27 , 'R' : show ((map properFraction small_float_list) :: [(Int,Float)])
28 , 'S' : show ((map properFraction float_list) :: [(Integer,Float)])
29 , 'T' : show ((map properFraction small_double_list) :: [(Int,Double)])
30 , 'U' : show ((map properFraction double_list) :: [(Integer,Double)])
31 ]
32 where
33 -- these fit into an Int when truncated. Truncation when the
34 -- result does not fit into the target is undefined - not explicitly
35 -- so in Haskell 98, but that's the interpretation we've taken in GHC.
36 -- See bug #1254
37 small_float_list :: [Float]
38 small_float_list = [
39 0.0, -0.0, 1.1, 2.8, 3.5, 4.5, -1.0000000001, -2.9999995,
40 -3.50000000001, -4.49999999999, 1000012.0, 123.456, 100.25,
41 102.5, 0.0012, -0.00000012, 1.7e4, -1.7e-4, 0.15e-6, pi
42 ]
43
44 float_list :: [Float]
45 float_list = small_float_list ++ [
46 1.18088e+11, 1.2111e+14
47 ]
48
49 -- these fit into an Int
50 small_double_list :: [Double]
51 small_double_list = [
52 0.0, -0.0, 1.1, 2.8, 3.5, 4.5, -1.0000000001, -2.9999995,
53 -3.50000000001, -4.49999999999, 1000012.0, 123.456, 100.25,
54 102.5, 0.0012, -0.00000012, 1.7e4, -1.7e-4, 0.15e-6, pi
55 ]
56
57 double_list :: [Double]
58 double_list = small_double_list ++ [
59 1.18088e+11, 1.2111e+14
60 ]