Backport from sid to buster
[hcoop/debian/mlton.git] / regression / ieee-real.sml
CommitLineData
7f918cf1
CE
1structure R = Real
2structure I = IEEEReal
3structure V = Word8Vector
4structure P = PackRealBig
5
6fun setRM mode =
7 (I.setRoundingMode mode;
8 if I.getRoundingMode () <> mode
9 then raise Fail "setRM"
10 else ())
11
12fun up() = setRM I.TO_POSINF
13fun down() = setRM I.TO_NEGINF
14fun near() = setRM I.TO_NEAREST
15fun zero() = setRM I.TO_ZERO
16
17 (*
18
19 61 digits of 1 / 10 in Mathematica
20
21 In[7]:= RealDigits[1 / 10,2,61]
22
23 Out[7]= {{1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
24 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
25 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
26 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
27 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
28 0, 1, 1, 0, 0, 1, 1, 0, 0, 1},-3}
29
30 *)
31
32
33val mtenth_lo = (down();1.0 / 10.0)
34val mtenth_hi = (up();1.0 / 10.0)
35val mtenth_near = (near();1.0 / 10.0)
36val mtenth_zero = (zero();1.0 / 10.0)
37
38fun word8vectorToString v = V.foldr (fn(w,s) => Word8.toString w ^ s) "" v
39
40val _ = print(word8vectorToString (P.toBytes mtenth_lo) ^ "\n")
41val _ = print(word8vectorToString (P.toBytes mtenth_hi) ^ "\n")
42val _ = print(word8vectorToString (P.toBytes mtenth_near) ^ "\n")
43val _ = print(word8vectorToString (P.toBytes mtenth_zero) ^ "\n")