[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[2]: Language problems causes bugs not to be understood as the bug s they are



PureBytes Links

Trading Reference Links

On Monday, July 16, 2001, 4:15:11 PM, Bengtsson, Mats wrote:

BM> ******************************************
BM> {Test Indicator, must plot Zero line}
BM> Value1 = 10.387 - 10.280;
BM> Value2 = 10.280 - 10.173;
BM> If Value1 = Value2 Then Value1 = 0;
BM> plot1 (Value1);
BM> ******************************************

TS has trouble when two decimal values are compared (Val1 = Val2).
They are never truly equal if they are calculated from other numbers.
There are small errors from the precision of the computation. A
preferred approach is to allow a small error in the comparison:

Value3 = .000001 for example, then use:
if AbsValue (Value1 - Value2) < Value3 Then Value1 = 0;

This allows numbers to be "equal" within some error that will always
be there.

HTH,

ztrader