Import Upstream version 20180207
[hcoop/debian/mlton.git] / regression / pack-real.sml
1 functor Test (structure PackReal: PACK_REAL
2 structure Real: REAL
3 val tests: Real.real list
4 sharing type PackReal.real = Real.real) =
5 struct
6
7 val _ =
8 if List.all (fn r =>
9 let
10 val v = PackReal.toBytes r
11 val _ =
12 print (concat ["r = ", Real.fmt StringCvt.EXACT r, "\t"])
13 val _ =
14 Word8Vector.app
15 (fn w =>
16 let
17 val s = Word8.toString w
18 in
19 print (if String.size s = 1
20 then concat ["0", s]
21 else s)
22 end)
23 v
24 val _ = print "\n"
25 in
26 Real.== (r, PackReal.fromBytes v)
27 end)
28 tests
29 then ()
30 else raise Fail "failure"
31
32 end
33
34 val real32Tests =
35 let
36 open Real32
37 in
38 [negInf,
39 ~100.0,
40 ~1.1,
41 ~0.12345,
42 ~0.0,
43 0.0,
44 minPos,
45 minNormalPos,
46 1.0,
47 2.0,
48 123E6,
49 maxFinite,
50 posInf]
51 end
52
53 val real64Tests =
54 let
55 open Real64
56 in
57 [negInf,
58 ~100.0,
59 ~1.1,
60 ~0.12345,
61 ~0.0,
62 0.0,
63 minPos,
64 minNormalPos,
65 1.0,
66 2.0,
67 123E6,
68 maxFinite,
69 posInf]
70 end
71
72 structure Z = Test (structure PackReal = PackReal32Big
73 structure Real = Real32
74 val tests = real32Tests)
75 structure Z = Test (structure PackReal = PackReal32Little
76 structure Real = Real32
77 val tests = real32Tests)
78 structure Z = Test (structure PackReal = PackReal64Big
79 structure Real = Real64
80 val tests = real64Tests)
81 structure Z = Test (structure PackReal = PackReal64Little
82 structure Real = Real64
83 val tests = real64Tests)