Download MetaTrader 5
To add comments, please log in or register
Have you developed an application? Publish it in Code Base!
moonsboy
889
moonsboy 2016.01.19 03:33 

a. Double confirm with you that it's not necessary to use '2' below but ok to use '1' below to compare for "int" types. Correct? 

1.  if (a > b)




 2. if (a - b > Point / 2.)

 

 

b. How many digits does the number precision reach while need to use '2' for comparing? 

Keith Watford
Moderator
7947
Keith Watford 2016.01.19 04:37  
If comparing integers you have no need to worry about floating point precision.
Wang Qi
514
Wang Qi 2016.01.19 09:52  
"a > b" should always work as you expected.
whroeder1
13627
whroeder1 2016.01.19 13:02  
wqking: "a > b" should always work as you expected.
Wrong for doubles; it's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.) Double-precision floating-point format - Wikipedia, the free encyclopedia see The == operand. - MQL4 forum
Wang Qi
514
Wang Qi 2016.01.19 13:26  
WHRoeder:
Wrong for doubles; it's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.) Double-precision floating-point format - Wikipedia, the free encyclopedia see The == operand. - MQL4 forum


OP was talking about the operator ">", not "==".

whroeder1
13627
whroeder1 2016.01.19 14:24  

Same thing. If because of floating point round off what should be equal could be come greater.

IF you want to open when price exceeds the last bar high, Bid > High[1] could be true when Bid == High[1] because of round off. If that is unacceptable equality is important.

If the possibility of equality is important, you must understand the links posted.

IF point is 0.00001 then 0.999995000000 is the same price as 1.000004999999 but they are not equal.

Keith Watford
Moderator
7947
Keith Watford 2016.01.19 21:33  

The OP was asking about comparing integers

jollydragon:

 

a. Double confirm with you that it's not necessary to use '2' below but ok to use '1' below to compare for "int" types. Correct? 

moonsboy
889
moonsboy 2016.01.20 01:14  
GumRai:

The OP was asking about comparing integers

 

 

 

Thank you. But who can help clarify on this question:

b. How many digits does the number precision reach while need to use formula '2' for comparing?  

whroeder1
13627
whroeder1 2016.01.20 13:27  
  1. GumRai: The OP was asking about comparing integers
    2. if (a - b > Point / 2.) (or a > b + Point/2) is for floating point. Price A is definitely greater then B

  2. jollydragon: b. How many digits does the number precision reach while need to use formula '2' for comparing? 
    The digits in Point.
    IF point is 0.00001 then 0.999995000000 is the same price as 1.000004999999 i.e. 1.00000 but they are not equal.
/
To add comments, please log in or register