(0.7 - 0.5) does not equal 0.2

Back to topics list To post a new topic, please log in or register
avatar
62
nikolaygmt 2016.02.27 17:43
 

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! 

avatar
62
nikolaygmt 2016.02.27 18:26 #
 

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


 

avatar
125
zirkoner 2016.02.27 18:42 #
 
avatar
62
nikolaygmt 2016.02.27 18:50 #
 
Hi zirkoner, thanks!
avatar
12998
WHRoeder 2016.02.27 19:08 #
 

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?

  1. There is no problem; it is you not understanding floating point. The == operand. - MQL4 forum Not all values can be exactly represented.
  2. Follow the link.
  3. There is no bug
  4. There is no public list.



avatar
62
nikolaygmt 2016.02.27 19:12 #
 
Thank you WHRoeder!
Back to topics list  

To add comments, please log in or register