raz / conform / run / RealRead.raz

35 lines · 1.0 KiB · raw · history · last change 264716cb

1(* Real literals read to the nearest F64, ties to the even one: their
2 bits, for numbers a reader of decimals easily gets one off. *)
3module RealRead;
4import Out;
5import SYSTEM;
6
7proc bits(x: F64): U64;
8var p: ^U64;
9begin
10 p := ^U64(SYSTEM.ADR(x));
11 return p^;
12end;
13
14proc show(x: F64);
15begin
16 Out.hex(bits(x), 16); Out.ln;
17end;
18
19proc main*;
20begin
21 show(5.319372648326541E255);
22 show(0.1);
23 show(2.2250738585072011E-308); (* just below the least normal *)
24 show(4.9E-324); (* the least F64 *)
25 show(2.4703282292062328E-324); (* just over half of it: up *)
26 show(2.4703282292062327E-324); (* just under: 0 *)
27 show(1.0E-400);
28 show(1.7976931348623157E308); (* the largest *)
29 show(9007199254740993.0); (* 2^53 + 1, a tie: down to even *)
30 show(9007199254740995.0); (* 2^53 + 3, a tie: up to even *)
31 show(1.00000000000000011102230246251565404236316680908203125); (* 1 + 2^-53, a tie *)
32 show(1.00000000000000011102230246251565404236316680908203126);
33end;
34
35end RealRead.