Comparison on double values / No need to round

 

Hi,

I found similar topics on Forum, but they sounded not quite same as my case, and decided to post this one.

I have following source code.

double SpanA_Buffer[], SpanB_Buffer[];

//These arrays are re-sized and also initialized as follow.

ArrayResize(SpanA_Buffer, a_begin-1);

ArrayInitialize(SpanA_Buffer, 0.0);

ArrayResize(SpanB_Buffer, Senkou-1);

ArrayInitialize(SpanB_Buffer, 0.0);

if (SpanA_Buffer[0] == SpanB_Buffer[0]) Print("Passed if (SpanA_Buffer[0] == SpanB_Buffer[0])");

Here is extracts from log file.

*** Successful case ***

SpanA_Buffer[0] = 0.8911 SpanB_Buffer[0] = 0.8911

Passed if (SpanA_Buffer[0] == SpanB_Buffer[0]

*** Failing case ***

SpanA_Buffer[0] = 0.8968 SpanB_Buffer[0] = 0.8968

I tried NormalizeDouble, but these values above do not really require to be rounded.

Moreover, when I tested with this function, values were rounded, and I couldn't get desirable result.

Majority of the comparison actually failed.

If someone could give me any advice, it would be much appreciated.

 
miko.szy: if (SpanA_Buffer[0] == SpanB_Buffer[0])
The == operand. - MQL4 forum
 

Thank you very much for your quick response.

I read through "working with doubles in MQL4" earlier, and checked and tested with some functions.

Now, I just changed the location of NormalizeDouble, from the section where I calculate values to the section where I actually assign the calculated result to the array.

Then result was very much improved!

Thank you for your help. Much appreciated.

 
miko.szy: I read through ... Now, I just changed the location of NormalizeDouble,
But apparently hard of reading. One of the links points out that I state that you should NEVER use NormalizeDouble for any reason. It's use is always wrong.
 

Yep. I read that, too, and I was not using the function in that case.

And, it was really good that your msg pushed me to read these information through once again, and I could think of a few other things I could give a try. ;)