raz / conform / run / ViewReals.raz

26 lines · 739 B · raw · history · last change f784f531

1(* Views of reals: their bits, read and written (report section 6.9) *)
2module ViewReals;
3import Out;
4
5var mem: [16]U8;
6
7proc main*;
8var x: F64; f: F32; u: U64; k: U32;
9begin
10 (* locals kept in registers otherwise *)
11 x := 1.5;
12 u := x.(U64);
13 Out.str("1.5's bits "); Out.hex(u, 16); Out.ln;
14 u := 4004000000000000H;
15 x.(U64) := u;
16 Out.str("x from bits, times 2: "); Out.int(I64(x * 2.0)); Out.ln;
17 f := 1.0;
18 k := f.(U32);
19 Out.str("F32 1.0's bits "); Out.hex(U64(k), 8); Out.ln;
20 (* a real in an array of bytes *)
21 mem[3].(F64) := 0.25;
22 Out.str("mem[3].(F64) times 8: "); Out.int(I64(mem[3].(F64) * 8.0)); Out.ln;
23 Out.str("its bits "); Out.hex(mem[3].(U64), 16); Out.ln;
24end;
25
26end ViewReals.