| 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. *) |
| 3 | module RealRead; |
| 4 | import Out; |
| 5 | import SYSTEM; |
| 6 | |
| 7 | proc bits(x: F64): U64; |
| 8 | var p: ^U64; |
| 9 | begin |
| 10 | p := ^U64(SYSTEM.ADR(x)); |
| 11 | return p^; |
| 12 | end; |
| 13 | |
| 14 | proc show(x: F64); |
| 15 | begin |
| 16 | Out.hex(bits(x), 16); Out.ln; |
| 17 | end; |
| 18 | |
| 19 | proc main*; |
| 20 | begin |
| 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); |
| 33 | end; |
| 34 | |
| 35 | end RealRead. |