Can price != price ? - page 3

 
WHRoeder:
At lot of computation instead of the simple solution
Simple or not is determined by the code that it needs to be implemented in . . .
 
RaptorUK:

I arrived at this solution which turns doubles into ints for the purpose of comparing doubles . . .

I, too, came up with a creative solution that has worked for me (so far) for comparing prices:

int ConvertToPoints (double _price) {
   double price_double = _price / Point;
   int price_int = MathRound(price_double);
      
   return (price_int);
}

I upscale the price to an int that represents price as points expressed as a whole number.  Thus:

ConvertToPoints(price) != ConvertToPoints(price)

can never be true.

 
Is CompareDoubles() from the stdlib.mq4 disqualified from this discussion? It works well for me if used for price.
 
Ovo:
Is CompareDoubles() from the stdlib.mq4 disqualified from this discussion? It works well for me if used for price.
Disqualified ? no, but all it does is a comparison for equality.
 
Thirteen:
ConvertToPoints(price) != ConvertToPoints(price)

A floating divide, floating addition, conversion to int, function call (copy, jump, return = 3,) * 2 all times two. (18) And that's assuming divide and convert are on par with the other operations - they are not.

vs

if (MathAbs(a - b) > Point / 2.)

one subtraction, one test, 1/2 negate (on average,) and comparison. (3 1/2 if point/2 is done in init and ABS is replaced by an IF)

Don't over complicate things

Could trigger when equal due to round off
if (a > b)
a is definitely larger than b
if (a - b > Point / 2.)
Could trigger when a is less than b due to round off
if (a >= b)
a is definitely >= b
if (a - b > -Point/2.)
if (a > b -Point/2.)
if (a +Point/2. > b)
Will trigger on any rounding error
 
if (a != b)
Definitely not equal
if (MathAbs(a - b) > Point / 2.)
 
WHRoeder:

A floating divide, floating addition, conversion to int, function call (copy, jump, return = 3,) * 2 all times two. (18) And that's assuming divide and convert are on par with the other operations - they are not.

vs

one subtraction, one test, 1/2 negate (on average,) and comparison. (3 1/2 if point/2 is done in init and ABS is replaced by an IF)

Don't over complicate things

2013.04.03 17:39:12 TestSpeed-CompareDbls USDJPY,M5: MathAbs(a - b) 9000000 times in 266 ms.

 
2013.04.03 17:39:11 TestSpeed-CompareDbls USDJPY,M5: ConvertToPoints 9000000 times in 1887 ms.

2013.04.03 17:46:02 TestSpeed-CompareDbls USDJPY,M5: Flat(price) 9000000 times in 3604 ms.

 

"MathAbs(a-b)" method is approx 7 times faster than ConvertToPoints() method and almost 14 times faster than my "Flat()" method

 
For information, with MQL5, you can overload standard operators, this allows to implement very elegant solutions.
 
I've tested (intRecord > price / point) and 
      intCheck = price /point;
      if (intRecord > intCheck) continue;

2013.04.04 14:27:38 TestSpeed-CompareDbls EURUSD,H4: MathAbs(a - b) HalfAPoint 99999999 times in 3403 ms.

2013.04.04 14:27:42 TestSpeed-CompareDbls EURUSD,H4: (intRecord > intCheck) 99999999 times in 2505 ms.

2013.04.04 14:27:40 TestSpeed-CompareDbls EURUSD,H4: intRecord > price /point 99999999 times in 1712 ms.

But the 3-rd can't be practicably, and the 2-nd one (intRecord > intCheck) had 1 assignment more within for the  intCheck before comparison.


 
rfb:
I've tested (intRecord > price / point) and 

2013.04.04 14:27:38 TestSpeed-CompareDbls EURUSD,H4: MathAbs(a - b) HalfAPoint 99999999 times in 3403 ms.

2013.04.04 14:27:42 TestSpeed-CompareDbls EURUSD,H4: (intRecord > intCheck) 99999999 times in 2505 ms.

2013.04.04 14:27:40 TestSpeed-CompareDbls EURUSD,H4: intRecord > price /point 99999999 times in 1712 ms.

But the 3-rd can't be practicably, and the 2-nd one (intRecord > intCheck) had 1 assignment more within for the  intCheck before comparison.


What is intRecord ?
 
Same as "int intCheck" but assigned value before the function, like other vars.