There has been some discussion of this topic. In summary:
Robert wrote:
The following code returns TRUE; should it, or is this a bug?
VAR
k : INTEGER
BEGIN
k := 33;
RETURN k IN {1}
Doug wrote:
It appears (via simulation) that all values for
k = 2^n + 1, for n= 5, ..., 31
also return TRUE.
33 IN {1} $TRUE
65 IN {1} $TRUE
129 IN {1} $TRUE
257 IN {1} $TRUE
513 IN {1} $TRUE
1025 IN {1} $TRUE
2049 IN {1} $TRUE
4097 IN {1} $TRUE
8193 IN {1} $TRUE
16385 IN {1} $TRUE
32769 IN {1} $TRUE
65537 IN {1} $TRUE
131073 IN {1} $TRUE
262145 IN {1} $TRUE
524289 IN {1} $TRUE
1048577 IN {1} $TRUE
2097153 IN {1} $TRUE
4194305 IN {1} $TRUE
8388609 IN {1} $TRUE
16777217 IN {1} $TRUE
33554433 IN {1} $TRUE
67108865 IN {1} $TRUE
134217729 IN {1} $TRUE
268435457 IN {1} $TRUE
536870913 IN {1} $TRUE
1073741825 IN {1} $TRUE
-2147483647 IN {1} $TRUE
Robert wrote:
My guess would be that it only considers (k MOD 32), but should it?
Incidentally (k IN {1}) is a compile time error if k is a CONSTant of 33.
Doug wrote:
I've found an example of the thought processes used but not
the inner guts of IN. See Dialog.In
PROCEDURE (VAR s: Selection) In* (index: INTEGER): BOOLEAN, NEW;
BEGIN
IF s.l.items = NIL THEN Init(s.l); s.len := s.l.len END;
IF s.sel # NIL THEN RETURN (index MOD 32) IN (s.sel[index DIV 32]) ELSE RETURN FALSE END
END In;
I agree with you and yes if k is a constant the compiler finds it.
32 < k should fail for k IN set, for all sets.
Now we need to find where in the code MOD 32 operation is
being applied when it shouldn't.
Robert wrote:
Does “fail” mean return FALSE, or TRAP?
Doug wrote:
I think it should be FALSE.