Are System.Double operators overloaded for epsilon?

D

David Veeneman

Are System.Double operators overloaded to perform epsilon comparisons, or do
these comparisons have to be performed by the programmer. In other words, if
I have two doubles, A and B, and I test "A > B", does C# do a strict
mathematical comparison, or does it do a "A - B > Double.Epsilon"
comparison? Thanks
 
N

Nicholas Paldino [.NET/C# MVP]

David,

I don't believe that epsilon is used in comparisons. If you need to
assure a degree of precision, then use the Decimal class, which will
guarantee precision (and therefore, remove the need for epsilons).

Hope this helps.
 
O

Octavio Hernandez

David,

I believe the equality comparison is based on the binary pattern of the
operands, except for special cases (NaN).
It is programmer's responsibility to check against an Epsilon instead of
using '==' on floating point values.

Regards - Octavio
 
J

Jon Skeet [C# MVP]

Nicholas Paldino said:
I don't believe that epsilon is used in comparisons. If you need to
assure a degree of precision, then use the Decimal class, which will
guarantee precision (and therefore, remove the need for epsilons).

Decimal doesn't guarantee precision - it certainly doesn't prevent
rounding errors etc. It just changes the set of numbers which can be
exactly represented.
 
C

Christoph Nahr

They are not. IMO it's a good thing that they aren't since that would
be counter-intuitive, but I certainly would applaud an additional set
of standard methods to perform epsilon comparisons on floats &
doubles. I asked David Notario but I don't think he'll do it. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top