summaryrefslogtreecommitdiff
path: root/testsuite/tests/numeric/should_run/arith012.hs
blob: f9f9ec778e8da91267983605559b9a57e5919ee6 (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
81
82
83
84
85
86
87
88
89
90
-- !!! Testing NumExts
module Main(main) where

import Numeric
import Data.Char

main :: IO ()
main = tst

tst :: IO ()
tst = do
  test_doubleToFloat
  test_floatToDouble
  test_showHex
  test_showOct
  test_showBin

----
-- Test data:
doubles :: [Double]
doubles = [ -1.2 , 0, 0.1, 0.5, 1.0, 1234.45454, 
           1.6053e4, 1.64022e12, 6.894e-4, 6.34543455634582173,
	   5342413403.40540423255]
ints :: [Int]
ints = [ 0, 1, 255, 65513, 6029, 1024, 256, 201357245]

integers :: [Integer]
integers = [ 0, 1, 255, 65513, 6029, 1024, 256,
	    2343243543500233, 656194962055457832]
---

test_doubleToFloat :: IO ()
test_doubleToFloat = do
  test_banner "doubleToFloat"
  putStrLn (show doubles)
  putStrLn (show $ map doubleToFloat doubles)

doubleToFloat :: Double -> Float
doubleToFloat = realToFrac

floatToDouble :: Float -> Double
floatToDouble = realToFrac

test_floatToDouble :: IO ()
test_floatToDouble = do
  test_banner "doubleToFloat"
  putStrLn (show doubles)
  putStrLn (show $ map doubleToFloat doubles)
  putStrLn (show $ map (floatToDouble.doubleToFloat) doubles)

test_showHex :: IO ()
test_showHex = do
  test_banner "showHex"
  putStrLn (show ints)
  putStrLn (showList' (map showHex ints))
  putStrLn (show integers)
  putStrLn (showList' (map showHex integers))

test_showBin :: IO ()
test_showBin = do
  test_banner "showBin"
  putStrLn (show ints)
  putStrLn (showList' (map showBin ints))
  putStrLn (show integers)
  putStrLn (showList' (map showBin integers))

showBin i = showIntAtBase 2 intToDigit i

showList' :: [ShowS] -> String
showList' [] = "[]"
showList' (x:xs) = showChar '[' . x $ showl xs ""
      where 
       showl []     = showChar ']'
       showl (x:xs) = showChar ',' . x . showl xs


test_showOct :: IO ()
test_showOct = do
  test_banner "showOct"
  putStrLn (show ints)
  putStrLn (showList' (map showOct ints))
  putStrLn (show integers)
  putStrLn (showList' (map showOct integers))

----
test_banner :: String -> IO ()
test_banner tst = do
  putStrLn $ "--------------------------------"
  putStrLn $ "--Testing " ++ tst
  putStrLn $ "--------------------------------"