I know that I am using SHORT to type convert an out of range LONGINT, but I thought that SHORT did not do range checking. However this code TRAPs at run time.
Maybe there is a good correct solution. I can immediately think of three possiblities:
- Replace SHORT by SYSTEM.VAL
- Subtract 1/2 from r
- Use the empty code procedure (the added '~' is there to fool phpBB!)
Code: Select all
PROCEDURE [co~de] Low* (m : LONGINT) : INTEGER;
[Postscript: I have now tried the "Low" option, which I prefer, and it works.]
My point is that "s" is the correct result that I want, but "t" causes a TRAP.
Surely one should expect the expressions for both "s" & "t" to behave the same - I think this difference is a bug.
Code: Select all
PROCEDURE RandomSet*;
CONST
twoPwr = 4294967296.; (* 2^32 *)
VAR
r: REAL; m: LONGINT; s, t: SET;
BEGIN
r := 0.999999;
m := ENTIER (r * twoPwr);
s := BITS (SHORT (m));
t := BITS (SHORT (ENTIER (r * twoPwr)))
END RandomSet;