I get false results when I use comparison operators with Packed subrange types.
For example if X is of a packed user defined type, and is equal to 64, then "X >
63" yields false !
And when I try to solve it, the packed subrange type I define is no longer really
packed !
Here is a program to illustrate this problem :
(The bug appears if X > 63)
---------------------------------------------------------------------------
Program Bug01;
Const
XValueMax = 125;
Type
T_XValue = Packed 0..XValueMax;
Var
X : T_XValue;
Begin
Writeln;
Write('X ? ');
Readln(X);
Writeln('X = ',X);
Writeln('X > 63 : ',X > 63); {BUG}
Writeln('X < 63 : ',X < 63); {BUG}
Writeln('X = 63 : ',X = 63);
Writeln('X >= 63 : ',X >= 63); {BUG}
Writeln('X <= 63 : ',X <= 63); {BUG}
Writeln('X <> 63 : ',X <> 63); {BUG}
Writeln('Real(X) > 63 : ',Real(X) > 63);
Writeln('Real(X) < 63 : ',Real(X) < 63);
Writeln('Real(X) = 63 : ',Real(X) = 63);
Writeln('Real(X) >= 63 : ',Real(X) >= 63);
Writeln('Real(X) <= 63 : ',Real(X) <= 63);
Writeln('Real(X) <> 63 : ',Real(X) <> 63);
Writeln('X > Real(63) : ',X > Real(63));
Writeln('X < Real(63) : ',X < Real(63));
Writeln('X = Real(63) : ',X = Real(63));
Writeln('X >= Real(63) : ',X >= Real(63));
Writeln('X <= Real(63) : ',X <= Real(63));
Writeln('X <> Real(63) : ',X <> Real(63));
Writeln('Integer(X) > 63 : ',Integer(X) > 63); {BUG}
Writeln('X > Integer(63) : ',X > Integer(63)); {BUG}
End.
---------------------------------------------------------------------------
Here is the surprising output if I enter the value "64" :
X ? 64
X = 64
X > 63 : False
X < 63 : False
X = 63 : False
X >= 63 : True
X <= 63 : True
X <> 63 : True
Real(X) > 63 : True
Real(X) < 63 : False
Real(X) = 63 : False
Real(X) >= 63 : True
Real(X) <= 63 : False
Real(X) <> 63 : True
X > Real(63) : True
X < Real(63) : False
X = Real(63) : False
X >= Real(63) : True
X <= Real(63) : False
X <> Real(63) : True
Integer(X) > 63 : False
X > Integer(63) : False
The difference between: "Integer(X) > 63 : False" and "Real(X) > 63 : True" is
really surprising.
There is another bug.
If I define :
----------
Const
XValueMax :Byte = 125;
Type
T_XValue = Packed 0..XValueMax;
----------
or
----------
Const
XValueMax = 125;
Type
T_XValue = 0..XValueMax;
----------
then the results are good but "T_XValue" is now the 32 bits Integer type !
You can give to X a very large value (and a negative one if compiled with an older
version of GPC).
(Unsigned integer if compiled with "gpc version 20000718, based on 2.95.2
19991024 (release)" ; signed integer when compiled with "gpc version 19990503,
based on gcc-2.8.1")
I suppose it is a known bug ["There are some bugs with mathematical functions."
(more details in the bugs list would be helpful)]
and maybe it's related to the following one :
"Files of integer subranges that would fit in a byte do not; instead they are
handled as files of integer."
But I read no details about this problem in the documentation.
What do you think of it ?
Hope this helps
--
"Couperin"