Commit b7d8b035 authored by sewardj's avatar sewardj
Browse files

[project @ 2001-12-20 15:24:44 by sewardj]

Add test of floating-point comparisons in the presence of NaNs.
parent 1f8d5b00
......@@ -23,3 +23,4 @@ test "arith015" { vtr("", "", "") }
test "num009" { vtr("", "", "") }
test "num010" { vtr("", "", "") }
test "num011" { vtr("", "", "") }
test "arith016" { vtr("-fglasgow-exts", "", "") }
module Main where
import PrelGHC
import PrelBase
import PrelFloat
fcmp_eq, fcmp_ne, fcmp_lt, fcmp_le, fcmp_gt, fcmp_ge :: (String, Float -> Float -> Bool)
fcmp_eq = ("==", \ (F# a) (F# b) -> a `eqFloat#` b)
fcmp_ne = ("/=", \ (F# a) (F# b) -> a `neFloat#` b)
fcmp_lt = ("< ", \ (F# a) (F# b) -> a `ltFloat#` b)
fcmp_le = ("<=", \ (F# a) (F# b) -> a `leFloat#` b)
fcmp_gt = ("> ", \ (F# a) (F# b) -> a `gtFloat#` b)
fcmp_ge = (">=", \ (F# a) (F# b) -> a `geFloat#` b)
float_fns = [fcmp_eq, fcmp_ne, fcmp_lt, fcmp_le, fcmp_gt, fcmp_ge]
float_vals :: [Float]
float_vals = [0.0, 1.0, read "NaN"]
float_text
= [show4 arg1 ++ " " ++ fn_name ++ " " ++ show4 arg2 ++ " = " ++ show (fn arg1 arg2)
| (fn_name, fn) <- float_fns,
arg1 <- float_vals,
arg2 <- float_vals
]
where
show4 x = take 4 (show x ++ repeat ' ')
main
= putStrLn (unlines float_text)
0.0 == 0.0 = True
0.0 == 1.0 = False
0.0 == NaN = False
1.0 == 0.0 = False
1.0 == 1.0 = True
1.0 == NaN = False
NaN == 0.0 = False
NaN == 1.0 = False
NaN == NaN = False
0.0 /= 0.0 = False
0.0 /= 1.0 = True
0.0 /= NaN = True
1.0 /= 0.0 = True
1.0 /= 1.0 = False
1.0 /= NaN = True
NaN /= 0.0 = True
NaN /= 1.0 = True
NaN /= NaN = True
0.0 < 0.0 = False
0.0 < 1.0 = True
0.0 < NaN = False
1.0 < 0.0 = False
1.0 < 1.0 = False
1.0 < NaN = False
NaN < 0.0 = False
NaN < 1.0 = False
NaN < NaN = False
0.0 <= 0.0 = True
0.0 <= 1.0 = True
0.0 <= NaN = False
1.0 <= 0.0 = False
1.0 <= 1.0 = True
1.0 <= NaN = False
NaN <= 0.0 = False
NaN <= 1.0 = False
NaN <= NaN = False
0.0 > 0.0 = False
0.0 > 1.0 = False
0.0 > NaN = False
1.0 > 0.0 = True
1.0 > 1.0 = False
1.0 > NaN = False
NaN > 0.0 = False
NaN > 1.0 = False
NaN > NaN = False
0.0 >= 0.0 = True
0.0 >= 1.0 = False
0.0 >= NaN = False
1.0 >= 0.0 = True
1.0 >= 1.0 = True
1.0 >= NaN = False
NaN >= 0.0 = False
NaN >= 1.0 = False
NaN >= NaN = False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment