!= evaluates to true when equal - page 2

 
I think normalization is only useful for OrderSend() function.
And you should avoid "!=" or "==" for double values, if you can.
Better use ">=" and "<=".
 
sub,

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.