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"
Couperin a écrit :
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.
I suppose that you have ineed found a bug. To understand what is going on I have added a declaration
var Y: byte absolute X;
which enables to examine the binary contents of X. It is the same (at least for x=64) and all tests work as expected if you replace X by Y
???
Le 29 Jul 2000, à 22:12, Couperin a écrit:
I get false results when I use comparison operators with Packed subrange types.
Another try with a slight difference in the program (with no packed type):
Type T_XValue = 0..125; Var X : T_XValue;
It's OK with X = 64 but now :
X ? 4000000000 X = 4000000000 X > 63 : False X < 63 : True X = 63 : False X >= 63 : False 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
with gpc version 20000727, based on 2.95.2 19991024 (release)
-- "Couperin"
-- "Couperin"
Hi
In the first email the problem centers around "packed" and I don't know what's it doing.
In the 2nd email, 4 followed by 9 zeros as an integer is a negative number, -294967296
Without typecasting the comparisons are expecting integers So if you change X in the comparisons to longint(X) you get the right results
Perhaps this narrows the problem a little
Russ