Double vs FLOAT - unclear MathFloor error - page 2

 
      float AUTOPRICE;
      float askP=NormalizeDouble(Ask,Digits)/NormalizeDouble(Point,Digits);
      float bidP=NormalizeDouble(Bid,Digits)/NormalizeDouble(Point,Digits);
      float Averab=((askP+bidP))/2.0;
      AUTOPRICE=MathFloor(Averab)*Point;
      Print("FLOAT  "+"  askP="+askP+" bidP="+bidP+" Averab="+DoubleToString(Averab,10)+" AUTOPRICE="+DoubleToString(AUTOPRICE,10));

      double AUTOPRICE2;
      double askP2=NormalizeDouble(Ask,Digits)/NormalizeDouble(Point,Digits);
      double bidP2=NormalizeDouble(Bid,Digits)/NormalizeDouble(Point,Digits);
      double Averab2=((askP2+bidP2))/2.0;
      AUTOPRICE2=MathFloor(Averab2)*Point;
      Print("DOUBLE  "+"  askP2="+askP2+" bidP2="+bidP2+" Averab2="+DoubleToString(Averab2,10)+" AUTOPRICE="+DoubleToString(AUTOPRICE2,10));

spread:2

2017.02.26 09:56:54.475 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: DOUBLE askP2=105143 bidP2=105141 Averab2=105142.0000000000 AUTOPRICE=1.0514200000

2017.02.26 09:56:54.475 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: FLOAT askP=105143 bidP=105141 Averab=105142.0000000000 AUTOPRICE=1.0514199734




spread:3

2017.02.26 09:57:47.832 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: DOUBLE askP2=105144 bidP2=105141 Averab2=105142.5000000000 AUTOPRICE=1.0514200000

2017.02.26 09:57:47.832 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: FLOAT askP=105144 bidP=105141 Averab=105142.5000000000 AUTOPRICE=1.0514199734


spread:4

2017.02.26 09:58:05.813 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: DOUBLE askP2=105145 bidP2=105141 Averab2=105143.000000 AUTOPRICE=1.0514200000

2017.02.26 09:58:05.813 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: FLOAT askP=105145 bidP=105141 Averab=105143.0000000000 AUTOPRICE=1.0514299870

spread:5

2017.02.26 09:58:39.495 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: DOUBLE askP2=105146 bidP2=105141 Averab2=105143.5000000000 AUTOPRICE=1.0514300000

2017.02.26 09:58:39.495 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: FLOAT askP=105146 bidP=105141 Averab=105143.5000000000 AUTOPRICE=1.0514299870


 
renamed the topic to be more specific about the problem.
 
Vladislav Andruschenko:

2017.02.26 09:58:05.813 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: DOUBLE askP2=105145 bidP2=105141 Averab2=105143.000000 AUTOPRICE=1.0514200000

The result is correct. Averab2 < 105143.

 
fxsaber:

The result is correct. Averab2 < 105143.

why? becauseAverab2=105143.0000000000

 
Vladislav Andruschenko:

Why?Averab2=105143.0000000000

Forum on trading, automated trading systems & strategy testing

Double vs FLOAT - unclear MathFloor error

fxsaber, 2017.02.26 08:27

The printout of the double number is about nothing. If you want to print the true value of double, you need to look at its bytes.

 
Vladislav Andruschenko:

Why? BecauseAverab2=105143.0000000000

becausehttps://www.mql5.com/ru/docs/math/mathfloor
 
fxsaber:

I see your point. Thank you, but this is as far as the unpriming is concerned.

But the real value inside the code is the same as after unpriming. I've checked it more than once,

I understand,

that double 1 = 1.0000000000000000000000000000112123515;

and so on.

:-( ok, the main thing is that the problem is solved with float

 

105143

after MathFloor(105143) =105142

even if 105143.000000000000000000001

but I think I know what you're talking about.

although no

Print(2+" MathFloor="+MathFloor(2));

2 MathFloor=2



why MathFloor(105143) =105142 I can't understand... (unless it's not105143 but105142.9999999999999999999999)

 
Vladislav Andruschenko:

why then...

becausehttps://www.mql5.com/ru/docs/convert/normalizedouble
 
Vladislav Andruschenko:

why then MathFloor(105143) =105142 I cannot understand... (unless it's not105143, but105142.999999999999999999999999)

#define TOSTRING(A) #A + " = " + (string)(A) + " "

void OnStart()
{
  double Price1 = 105143;
  double Price2 = Price1 - 1 e-11;

  Print(TOSTRING(Price1) + TOSTRING(MathFloor(Price1)) +
        TOSTRING(Price2) + TOSTRING(MathFloor(Price2)) +
        TOSTRING(Price1 > Price2));
}
Result
Price1 = 105143.0 MathFloor(Price1) = 105143.0 Price2 = 105143.0 MathFloor(Price2) = 105142.0 Price1>Price2 = true

You shouldn't take double-numbers literally. Switching to float is even more of a pitfall.