1 -- !!! Testing IEEE Float and Double extremity predicates.
2 module Main(main) where
6 sequence (map putStrLn double_tests)
7 sequence (map putStrLn float_tests)
9 double_tests = run_tests double_numbers
10 float_tests = run_tests float_numbers
23 double_numbers :: [Double]
26 , encodeFloat 0 0 -- 0 using encodeFloat method
27 , encodeFloat 1 2047 -- +Inf
29 , encodeFloat 1 2047 -- signalling NaN
30 , encodeFloat 0xf000000000000 2047 -- quiet NaN
33 , 1.82173691287639817263897126389712638972163e-300
34 , 1.82173691287639817263897126389712638972163e+300
35 , 4.9406564558412465e-324 -- smallest possible denorm number
36 -- (as reported by enquire running
37 -- on a i686-pc-linux.)
38 , 2.2250738585072014e-308
43 , let (l, _) = floatRange x
44 x = encodeFloat 1 (l-1)
47 , let (_, u) = floatRange x
49 x = encodeFloat (floatRadix x ^ d - 1) (u - d)
53 float_numbers :: [Float]
56 , encodeFloat 0 0 -- 0 using encodeFloat method
57 , encodeFloat 1 255 -- +Inf
59 , encodeFloat 11 255 -- signalling NaN
60 , encodeFloat 0xf00000 255 -- quiet NaN
63 , 1.82173691287639817263897126389712638972163e-300
64 , 1.82173691287639817263897126389712638972163e+300
72 , let (l, _) = floatRange x
73 x = encodeFloat 1 (l-1)
76 , let (_, u) = floatRange x
78 x = encodeFloat (floatRadix x ^ d - 1) (u - d)
84 denorm :: RealFloat a => [a] -> String
88 : "*********************************"
89 : ("Denormalised numbers: " ++ doubleOrFloat numbers)
91 : map showPerform numbers)
93 showPerform = showAndPerform (isDenormalized) "isDenormalised"
95 pos_inf :: RealFloat a => [a] -> String
99 : "*********************************"
100 : ("Positive Infinity: " ++ doubleOrFloat numbers)
102 : map showPerform numbers)
104 showPerform = showAndPerform (isInfinite) "isInfinite"
106 neg_inf :: RealFloat a => [a] -> String
110 : "*********************************"
111 : ("Negative Infinity: " ++ doubleOrFloat numbers)
113 : map showPerform numbers)
115 showPerform = showAndPerform (\ x -> isInfinite x && x < 0) "isNegInfinite"
117 nan :: RealFloat a => [a] -> String
121 : "*********************************"
122 : ("NaN: " ++ doubleOrFloat numbers)
124 : map showPerform numbers)
126 showPerform = showAndPerform (isNaN) "isNaN"
128 pos_zero :: RealFloat a => [a] -> String
132 : "*********************************"
133 : ("Positive zero: " ++ doubleOrFloat numbers)
135 : map showPerform numbers)
137 showPerform = showAndPerform (==0) "isPosZero"
139 neg_zero :: RealFloat a => [a] -> String
143 : "*********************************"
144 : ("Negative zero: " ++ doubleOrFloat numbers)
146 : map showPerform numbers)
148 showPerform = showAndPerform (isNegativeZero) "isNegativeZero"
151 doubleOrFloat :: RealFloat a => [a] -> String
153 | (floatDigits atType) == (floatDigits (0::Double)) = "Double"
154 | (floatDigits atType) == (floatDigits (0::Float)) = "Float"
155 | otherwise = "unknown RealFloat type"
157 atType = undefined `asTypeOf` (head ls)
161 showAndPerform :: (Show a, Show b)
166 showAndPerform fun name_fun val =
167 name_fun ++ ' ':show val ++ " = " ++ show (fun val)