Wrong < or > Boolean Result Using Real Function As 2nd Operand PSS ID Number: Q70420 Article last modified on 04-03-1991 PSS database name: S_QuickPas
1.00
MS-DOS
Summary:
When a function that returns a floating-point value is used as an operand on the right-hand side of a relational expression using “>” or “<”, the resulting boolean value may be incorrect.
Microsoft has confirmed this to be a problem with Microsoft QuickPascal version 1.00 for MS-DOS. We are researching this problem and will post new information here as it becomes available.
More Information:
The following sample code demonstrates the problem:
function test: real; {returns value of 3} begin test := 3; end; begin {function as 2nd operand - results can be incorrect} if 2>test then writeln ('This IF is incorrectly shown TRUE.'); writeln (2>test); {'TRUE' incorrect} writeln (3=test); {'TRUE' correct} writeln (4>test); {'FALSE' incorrect} writeln (2<test); {'FALSE' incorrect} writeln (4<test); {'TRUE' incorrect} {function as first operand - results correct} writeln (test>2); {'TRUE' correct} writeln (test=3); {'TRUE' correct} writeln (test>4); {'FALSE' correct} writeln (test<2); {'FALSE' correct} writeln (test<4); {'TRUE' correct} end.
This problem occurs only if the value returned by the function is a floating-point value. If the value returned by the function is an integer type, then no problems occur.
As a workaround to this problem, if the returned value of the function must be used as the second operand in the expression, then put the returned value of the function into a variable and use that variable in the expression.
x := test writeln (4 > x); {'TRUE' correct}
Copyright Microsoft Corporation 1991.