Is there any reason I should use any of the value comparison methods
PublicFunctions.DoubleEquals()
PublicFunctions.DoubleGreater()
PublicFunctions.DoubleGreaterEquals()
PublicFunctions.DoubleLess()
PublicFunctions.DoubleLessEquals()
instead of C# operators: ==, >, >=, <, <=
I suppose the only reason for this redundancy is to get compiler verification on the parameters, i.e. lval and rval both have to be of type 'Double' or you will get a compiler error. Is that correct, or are there other reasons for it?
Thanks!
Public Functions for Comparing [SOLVED]
Yes, there is a reason - google for "floating point problem" or read:
http://docs.oracle.com/cd/E19957-01/806 ... dberg.html
In short, double cant store for example 0.1 precisely, so == will often fail when you dont expect it to fail, whereas these double compare functions will work as you probably intend.
http://docs.oracle.com/cd/E19957-01/806 ... dberg.html
In short, double cant store for example 0.1 precisely, so == will often fail when you dont expect it to fail, whereas these double compare functions will work as you probably intend.
I typically use type 'decimal' (System.Decimal) for anything that has to do with money. It is less prone to the floating point problem, but currently MultiCharts.NET does not support it as Input type. When I use decimal type for an input I get:
"The property 'xyz' with attribute "InputAttribute" must be a primitive type or System.String and must have public getter and public setter."
I think MultiCharts.NET should also use 'decimal' type throughout the APIs, anywhere that monetary amounts are inputted or outputted and in all calculations.
"The property 'xyz' with attribute "InputAttribute" must be a primitive type or System.String and must have public getter and public setter."
I think MultiCharts.NET should also use 'decimal' type throughout the APIs, anywhere that monetary amounts are inputted or outputted and in all calculations.