Errors, bugs, questions - page 2821

 
Igor Makanu:

normalisation is not rounding

I have an A+ in theory, how to work with double and so on. The NormalizeDouble algorithm contains an error. The topic raised is only indirectly related to comparing doubles.

 
fxsaber:

I repeat my question.

The picture shows the value of the non-normalised variable n and the normalised variable m and how different they are. But if you want to compare thongs, that's your preference.

fxsaber:

I know the theory, how to work with double and stuff like that on an A+ scale. The NormalizeDouble algorithm contains an error. The topic raised is only indirectly related to comparing doubles.

Definitely can't do without that Semko explanation here.
 
NormalizeDouble is just a certain algorithm that applies to a double number. Unfortunately, there is an error in it. If corrected, the error will disappear. The double representation of all the others will not change in any way.
 
fxsaber:

The NormalizeDouble algorithm contains an error.

yes

I think A100 wrote about it

but developers since MQL have been sticking to this "feature", alas


fxsaber:
If they correct it, the error will disappear.
I think other bugs will appear and there will be a lot of noise ))))
 
Igor Makanu:

I think other bugs will appear and there will be a lot of noise ))))

They won't, because almost everyone compares even normalised dubs through normalisation. I.e. they put it wherever they want.


Proper normalization should always give true in this condition.

Forum on trading, automated trading systems & strategy testing

Errors, bugs, questions

fxsaber, 2020.08.10 11:37

  Print((double)(string)Norm == Norm);    // false

This is the only valid check for normalization. If it will always give out true, then nothing will break.

 
fxsaber:
NormalizeDouble is just a certain algorithm that applies to a double number. Unfortunately, there is an error in it. If corrected, the error will disappear. All the other double-representations will not change as a result.
I think it's not about the function, but that constants are not normalized by the compiler (although they should be).
The same applies to converting string to double.
 
Alexey Navoykov:
I think it's not about the function, but that the constants are not normalized by the compiler (although they should be).
The same applies to string to double conversion.

Then the same constants in DLL and MQL will not match.

 
fxsaber:

Then the same constants in DLL and MQL will not match.

Also true. In addition any normalization is a loss of accuracy, so I may have gone too far with the normalization of constants.
In general, this problem, in my opinion, does not have an unambiguous solution. Although in fact it is not such a problem.
 
Alexey Navoykov:
Also true. Besides, any normalization is a loss of accuracy, so I may be overdoing it with constant normalization.
In general, this problem does not seem to me to have an unambiguous solution, although in essence it is not such a problem.

Just tweak the current normalisation algorithm.

 
fxsaber:

Just tweak the current normalisation algorithm.

void OnStart() {
   double d1=1.79435;
   double d2=NormalizeDouble(1.79435,5);
   Print(d1==d2);
   Print(is_equal(d1,d2,_Point/2));
}
//+------------------------------------------------------------------+
bool is_equal(double d1, double d2, double e=0.000000001) {return fabs(d1-d2)<e;}

I don't even know if this is a bug in the algorithm.
Really, you can't compare doubles. Just a hard rule.
Or, as Slava says, through epsilon or through multiplication (e.g. by 1/_Point) with conversion to int with rounding.

Only rounding is not done by round(), ceil(), floor() as they also return double.

Or through these, especially since they work faster than the regular ones:

int Ceil (double x) {return (x-(int)x>0)?(int)x+1:(int)x;}
int Round(double x) {return (x>0)?(int)(x+0.5):(int)(x-0.5);}
int Floor(double x) {return (x>0)?(int)x:((int)x-x>0)?(int)x-1:(int)x;}

Easier and faster, of course, through epsilon:

bool is_equal(double d1, double d2, double e=0.000000001) {return fabs(d1-d2)<e;}
Reason: