1 functor Basic(structure Real : REAL
2 structure Pack
: PACK_REAL
3 where type real = Real.real) =
6 val () = print
" Reported\n"
7 val () = print (" precision: " ^
Int.toString precision ^
"\n")
8 val {man
=_
, exp
} = toManExp maxFinite
9 val () = print (" max exponent: " ^
Int.toString exp ^
"\n")
10 val {man
=_
, exp
} = toManExp minNormalPos
11 val () = print (" min exponent: " ^
Int.toString exp ^
"\n")
12 val {man
=_
, exp
} = toManExp minPos
13 val () = print (" min denormal: " ^
Int.toString exp ^
"\n")
15 (* Now
let's compute the actual mantissa
*)
21 if eq (x
+one
, x
) then 0 else
22 Int.+ (1, precision
eq (x
+x
))
24 if eq (x
, x
+x
) then 0 else
25 Int.+ (1, maxExp
eq (x
+x
))
27 |
lowBit (i
, x
) = lowBit (Int.- (i
, 1), x
/ two
)
29 if not (eq (x
, (x
/ two
) * two
)) orelse eq (x
, zero
) then 1 else
30 Int.- (minExp
eq (x
/ two
), 1)
33 val xprecision
= precision eq one
34 val lastBit
= one
+ lowBit (xprecision
, one
)
35 val xmaxExp
= maxExp eq one
36 val xminNormalExp
= minExp eq lastBit
37 val xminExp
= minExp eq one
39 val () = print
" Actual\n"
40 val () = print (" precision: " ^
Int.toString xprecision ^
"\n")
41 val () = print (" max exponent: " ^
Int.toString xmaxExp ^
"\n")
42 val () = print (" min exponent: " ^
Int.toString xminNormalExp ^
"\n")
43 val () = print (" min denormal: " ^
Int.toString xminExp ^
"\n")
45 val a
= Word8Array
.array (Pack
.bytesPerElem
, 0w0
)
46 fun id x
= (Pack
.update (a
, 0, x
); Pack
.subArr (a
, 0))
48 val eq
= fn (x
, y
) => == (id x
, id y
)
49 val xprecision
= precision eq one
50 val lastBit
= one
+ lowBit (xprecision
, one
)
51 val xmaxExp
= maxExp eq one
52 val xminNormalExp
= minExp eq lastBit
53 val xminExp
= minExp eq one
55 val () = print
" Exported\n"
56 val () = print (" precision: " ^
Int.toString xprecision ^
"\n")
57 val () = print (" max exponent: " ^
Int.toString xmaxExp ^
"\n")
58 val () = print (" min exponent: " ^
Int.toString xminNormalExp ^
"\n")
59 val () = print (" min denormal: " ^
Int.toString xminExp ^
"\n")
62 val () = print
"Real32\n"
63 structure Z
= Basic(structure Real = Real32
64 structure Pack
= PackReal32Little
)
65 val () = print
"Real64\n"
66 structure Z
= Basic(structure Real = Real64
67 structure Pack
= PackReal64Big
)