//+------------------------------------------------------------------+//| Test whether two numbers are close to within "n" significant |//| digits of precision. |//+------------------------------------------------------------------+bool EqualDoubles(constdouble a, constdouble b, constint significantDigits = 15)
{
//--- https://stackoverflow.com/a/17382806returnMathAbs(a - b) < MathPow(10, -significantDigits) * MathMax(MathAbs(a), MathAbs(b));
}
@fxsaber Yes, you are right, I forgot that the expression got optimized out, coz its value was not used.
However, mine takes 0.04 microsec per call. Do you think it worth this micro-optimization over readability?!!
The percentage saved over a whole program = percentage function is called * percentage saved by optimization.
Surely, the 1st term of the equation is always way too small for this specific function. That is why profiling your program is sometimes more important to see the whole picture, rather than timing a single instruction.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Added a new function for comparing doubles:
Faster.
Faster.
Ugly!
Sure, it is faster but in interpreted languages like JavaScript, but not in MQL. See https://stackoverflow.com/a/48764436.
Sure, it is faster but in interpreted languages like JavaScript, but not in MQL. See https://stackoverflow.com/a/48764436.
You need to learn how to make proper performance measurements.
21 times faster.
@fxsaber Yes, you are right, I forgot that the expression got optimized out, coz its value was not used.
However, mine takes 0.04 microsec per call. Do you think it worth this micro-optimization over readability?!!
The percentage saved over a whole program = percentage function is called * percentage saved by optimization.
Surely, the 1st term of the equation is always way too small for this specific function. That is why profiling your program is sometimes more important to see the whole picture, rather than timing a single instruction.
Thanks for passing by. :-)However, mine takes 0.04 microsec per call. Do you think it worth this micro-optimization over readability?!!
In this case, I am definitely on the performance side. Readability is very easy for me.
In this case, I am definitely on the performance side. Readability is very easy for me.
I'm sure you are. take care.
It seems to me that such a modification of the condition is correct.