It turns out that there are many more errors like this:
double vals[] = {0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1};
int numOfVals = ArraySize(vals);
int lastValIndex = numOfVals - 1;
int resultIndex;
for (int curValIndex = 0; curValIndex < lastValIndex - 1; curValIndex++) {
// from 0.9 to 0.3
double curVal = vals[curValIndex];
for (int curSubValIndex = curValIndex + 1; curSubValIndex <= lastValIndex; curSubValIndex++) {
// from next to last
double curSubVal = vals[curSubValIndex];
resultIndex = lastValIndex - (curSubValIndex - curValIndex - 1);
Print(curVal + " - " + curSubVal + " == " + vals[resultIndex] + " returns ",
((curVal - curSubVal) == vals[resultIndex]) );
}
}
prints:
0.3 - 0.1 == 0.2 returns false
0.3 - 0.2 == 0.1 returns false
0.4 - 0.1 == 0.3 returns false
0.4 - 0.2 == 0.2 returns true
0.4 - 0.3 == 0.1 returns false
0.5 - 0.1 == 0.4 returns true
0.5 - 0.2 == 0.3 returns true
0.5 - 0.3 == 0.2 returns true
0.5 - 0.4 == 0.1 returns false
0.6 - 0.1 == 0.5 returns true
0.6 - 0.2 == 0.4 returns false
0.6 - 0.3 == 0.3 returns true
0.6 - 0.4 == 0.2 returns false
0.6 - 0.5 == 0.1 returns false
0.7 - 0.1 == 0.6 returns true
0.7 - 0.2 == 0.5 returns false
0.7 - 0.3 == 0.4 returns false
0.7 - 0.4 == 0.3 returns false
0.7 - 0.5 == 0.2 returns false
0.7 - 0.6 == 0.1 returns false
0.8 - 0.1 == 0.7 returns false
0.8 - 0.2 == 0.6 returns false
0.8 - 0.3 == 0.5 returns true
0.8 - 0.4 == 0.4 returns true
0.8 - 0.5 == 0.3 returns false
0.8 - 0.6 == 0.2 returns false
0.8 - 0.7 == 0.1 returns false
0.9 - 0.1 == 0.8 returns true
0.9 - 0.2 == 0.7 returns true
0.9 - 0.3 == 0.6 returns false
0.9 - 0.4 == 0.5 returns true
0.9 - 0.5 == 0.4 returns true
0.9 - 0.6 == 0.3 returns false
0.9 - 0.7 == 0.2 returns false
0.9 - 0.8 == 0.1 returns false
nikolaygmt: 0.7-0.5 does not equal 0.2. T
1) How to fix this problem?
2) Are there any other similar problems?
3) How to report this bug to the MT4 developers?
4) How to find all official MT4 bugs?
- There is no problem; it is you not understanding floating point. The == operand. - MQL4 forum Not all values can be exactly represented.
- Follow the link.
- There is no bug
- There is no public list.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
0.7-0.5 does not equal 0.2. To test it you can use the following code:
Print("Test 0.7-0.5==0.2 Result: ", (0.7 - 0.5) == 0.2);
which should print:
Test 0.7-0.5==0.2 Result: false
I am using: MT4 Version 4.00 Build 920 (26 Nov 2015) and 940 (03 Dec 2015) on Windows 7, 64bit. Installation folder: "C:\Program Files (x86)"
Do you know:
1) How to fix this problem?
2) Are there any other similar problems?
3) How to report this bug to the MT4 developers?
4) How to find all official MT4 bugs?
Thank you!