Errors, bugs, questions - page 2820

 
Kira27:

The certificate confused me)))

The reference says without inverted commas. So you put yourself in there.

 
A bearded question. But I don't understand this result.
void OnStart()
{
  Print(NormalizeDouble(1.79435, 5) == 1.79435); // false  
}
 
fxsaber:
Bearded question. But I don't understand this result.

It has been said 100 times: "don't use exact dub comparison, use epsilon". Including in our documentation.

Not even 0.3 or 0.7 will compare with your perceptions. Accept it and get over it. Or go and learn (at MTI, for example)

 
Slava:

It has been said 100 times: "don't use exact dub comparison, use epsilon". Including in our documentation.

I know how to do a dub comparison, of course.

Not even 0.3 or 0.7 will compare to your perceptions. Accept it and get over it. Or go and learn (at MTI, for example).

Print(NormalizeDouble(0.3, 5) == 0.3); // true
Print(NormalizeDouble(0.7, 5) == 0.7); // true

Print(NormalizeDouble(0.12345, 5) == 0.12345); // true

You don't understand the question.

 
decimal would make it easier, but it's slow(
 
fxsaber:

I can do a dub comparison, of course.

You don't understand the question.

There are other subtleties.

A real number multiplied by 0.5 may not compare to the same number divided by 2.0

 
Slava:

There are other subtleties.

A real number multiplied by 0.5 may not equal the same number divided by 2.0

That's true. But the question was, why isn't the number 1.79435 normalized to 5 decimal places?


ZS The background to this question.

The SL in the Tester went off. DEAL_PRICE = 1.79435, ORDER_PRICE_OPEN = 0(as in MT5), DEAL_COMMENT = "sl 1.79435".

I wanted to know if there was a slip when I executed SL or not? So I simply compared DEAL_PRICE and the price from the comment. With my eyes I see that the prices are the same but MQL shows that they are not. Finally got to the bottom of the original comparison.

Forum on trading, automated trading systems & strategy testing

Errors, bugs, questions

fxsaber, 2020.08.10 09:04

void OnStart()
{
  Print(NormalizeDouble(1.79435, 5) == 1.79435); // false  
}
 
fxsaber:

All true. But the question was why is the number 1.79435 not normalised to the 5th decimal place?


ZS Background to the question.

The SL in the Tester was triggered. DEAL_PRICE = 1.79435, ORDER_PRICE_OPEN = 0(as in MT5), DEAL_COMMENT = "sl 1.79435".

I wanted to know if there was a slip when I executed SL or not? So I simply compared DEAL_PRICE and the price from the comment. With my eyes I see that the prices are the same but MQL shows that they are not. Ended up getting to the original comparison.

Sorry, but it's kind of strange to hear you say that.


 
Alexey Viktorov:

I'm sorry, but it's kind of strange to hear you say that.

I repeat my question.

fxsaber:

why is the number 1.79435 not normalised to the 5th decimal place?

void OnStart()
{
  const double Norm = NormalizeDouble(1.79435, 5);
  
  Print((double)(string)Norm == Norm);    // false
  Print((double)(string)Norm == 1.79435); // true
}
 
fxsaber:

All true. But the question was why is the number 1.79435 not normalised to the 5th decimal place?

normalization is not rounding.

@Slava writes that the internal representation of double is different:

#define  PRINT(EX) Print(#EX," = ",EX)
//+------------------------------------------------------------------+
void OnStart()
{
   union ULONG_DOUBLE
   {
      double d_value;
      ulong ul_value;
   }tmp;
   double NORM_DOUBLE   = NormalizeDouble(1.79435, 5);
   double CONST_DOUBLE  = 1.79435;
   
   PRINT(NORM_DOUBLE);
   tmp.d_value = NORM_DOUBLE;
   PRINT(LongToHex(tmp.ul_value));
   
   tmp.d_value = CONST_DOUBLE;
   PRINT(CONST_DOUBLE);
   PRINT(LongToHex(tmp.ul_value));
}
//+------------------------------------------------------------------+
string LongToHex(const ulong value)
{
   return(StringFormat("%llX", value));
}
//+------------------------------------------------------------------+

2020.08.10 13:33:37.737 tst_normalize (EURUSD,H1) NORM_DOUBLE = 1.79435

2020.08.10 13:33:37.737 tst_normalize (EURUSD,H1) LongToHex(tmp.ul_value) = 3FFCB5A858793DDA

2020.08.10 13:33:37.737 tst_normalize (EURUSD,H1) CONST_DOUBLE = 1.79435

2020.08.10 13:33:37.737 tst_normalize (EURUSD,H1) LongToHex(tmp.ul_value) = 3FFCB5A858793DD9


SZS: There was a good post@Nikolai Semko somewhere, he described work with double very well, maybe I'll find the link.

UPD:https://www.mql5.com/ru/forum/1111/page2623#comment_14473837