You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
And you should avoid "!=" or "==" for double values, if you can.
Better use ">=" and "<=".
You should have learnt from the article that a computer cannot store a double precisely if it cannot be represented by a combination of the -ve powers of 2 within the constraints of the type.
I would surmise that you cannot assign the result of the NormalizeDouble function to a variable. Therefore, you need to normalize a number whenever you are using it in a comparison. So, in your case:
a = 1.2 - 1.0;
if(NormalizeDouble(a, 4) == NormalizeDouble(0.2, 4)) {
// do something
}
By having to explicitly state when you want to normalize a number should theoretically improve the performance of the code. Otherwise, it is up to the compiler to make its own determination of whether to normalize depending on the context that the double is being used.