Features of the mql5 language, subtleties and tricks - page 240

 
Nikolai Semko #:

7 - Sunday

It'smore useful when Sunday is zero.

 
fxsaber #:

It'smore useful when Sunday is zero.

maybe then:

uchar WhatWeekDay(datetime t) {
   return uchar(t/(24*60*60)+4 )%7;
}
 
A mathematically identical expression (highlighted) can produce different results in practice.
template <typename T>
T MathMin1( const T Num1, const T Num2 )
{
  return(Num1 < Num2 ? Num1 : Num2);    
}

template <typename T>
T MathMin2( const T Num1, const T Num2 )
{
  return(Num1 <= Num2 ? Num1 : Num2);    
}

void OnStart()
{
  Print(MathMin1(0.0, -0.0)); // -0.0
  Print(MathMin2(0.0, -0.0)); // 0.0
}
 
fxsaber # : Mathematically the same expression (highlighted) can give different results in practice.

As long as the two amounts are equal, any one of them is a valid minimum. Consider MathMin(1, 1), it does not differ if the function returns the first (1) or second (1).

So, returning 0.0 is not different from -0.0.

Edit: by the way, the two highlighted expressions are NOT identical.
 
fxsaber #:
Mathematically the same expression (highlighted) can give different results in practice.

Well, it's different expressions, so the result is different. What's wrong here?

In the first case: 0 < 0? No. The second argument is returned.

In the second case: 0 <= 0? Yes. The first argument is returned.

 
Ihor Herasko #:

It's different expressions

fxsaber #:
Mathematically the same expression
 
fxsaber #:

The < and <= signs seem to be different.....

 
Ihor Herasko #:

The < and <= signs seem to be different.....

You refuse to understand.

 
fxsaber #:

You refuse to understand.

I don't understand why the highlighted expressions are mathematically the same either.

 
fxsaber #:

You refuse to understand.

Maybe I would if I knew the background of the situation. But as it stands, it looks right.