| 1 | (* Views of reals: their bits, read and written (report section 6.9) *) |
| 2 | module ViewReals; |
| 3 | import Out; |
| 4 | |
| 5 | var mem: [16]U8; |
| 6 | |
| 7 | proc main*; |
| 8 | var x: F64; f: F32; u: U64; k: U32; |
| 9 | begin |
| 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; |
| 24 | end; |
| 25 | |
| 26 | end ViewReals. |