Val2 - correct. Val3 after conversion to long - not correct. Apparently, it is some peculiarity of double representation of floating point numbers. We need to increment EPSILON. I can't make it out on my sleepy head. Maybe some knowledgeable people may give me a hint.
I need to figure out what considerations the developers used to write this
//+------------------------------------------------------------------+//| Сравнивает два значения типа double. |//| RESULT |//| Возвращает истину, если значения равны и |//| ложь в противном случе. |//+------------------------------------------------------------------+bool CEnvironment::DoubleEquals(constdouble a,constdouble b)
{
//---return(fabs(a-b)<=16*DBL_EPSILON*fmax(fabs(a),fabs(b)));
//---
}
DBL_EPSILON defines a difference of 1 (one!) significant bit of an exponent when applied to the number 1.0. In practice, there is no such difference - the numbers are either strictly equal or can differ by more than one significant bit. Therefore, you have to take something like 16*DBL_EPSILON to ignore the difference of 4 least significant bits (or about one and a half last significant decimal digits out of about 16 available).
Of course, there are cases where the range of numbers is more or less known and predictable. Say, 0...1000. In this case, you can take a constant like 1000*16*DBL_EPSILON for a rough comparison. But we must keep in mind that such a comparison actually turns the whole floating point idea into a fixed point (guess why).
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.
It turns out that #import ex5 is the evil of optimization.
In terms of being able to optimise globally, yes.
We have quite aggressive inlining without trying to make the code smaller. So in global optimization mode we generate very good code.
This can be seen in the compile time, where we put the resulting speed at the top of the list.
fxsaber
There is an error in your code
Thank you, corrected.
Still a mistake.
It should be a 5 at the end.
Still an error
This is not an error, it is rounding. That's how the standard version does it.
Here's the code for you to test
Here's your code, test it.
Val2 - correct. Val3 after conversion to long - not correct. Apparently, it is some peculiarity of double representation of floating point numbers. We need to increment EPSILON. I can't make it out on my sleepy head. Maybe some knowledgeable people may give me a hint.
I need to figure out what considerations the developers used to write this
This seems to be where the dog is buried.
This seems to be where the dog is buried.
The roots grow from the RSDN forum
Of course, there are cases where the range of numbers is more or less known and predictable. Say, 0...1000. In this case, you can take a constant like 1000*16*DBL_EPSILON for a rough comparison. But we must keep in mind that such a comparison actually turns the whole floating point idea into a fixed point (guess why).
A variant of CopyTicks, which is sometimes several orders of magnitude faster than the original (from > 0)