Re: Double comparisons for equality
- From: v-jetan@xxxxxxxxxxxxxxxxxxxx ("Jeffrey Tan[MSFT]")
- Date: Sat, 28 May 2005 07:55:36 GMT
Also, I think we'd better no use == for the floating point comparison, just
use subtract operation, and compare the result with a very "little"
number(a tolerance level), just as "Comparing floating point numbers"
section in the link below pointed out:
"One consequence of all of this is that you should very, very rarely be
comparing binary floating point numbers for equality directly. It's usually
fine to compare in terms of greater-than or less-than, but when you're
interested in equality you should always consider whether what you actually
want is near equality: is one number almost the same as another. One simple
way of doing this is to subtract one from the other, use Math.Abs to find
the absolute value of the difference, and then check whether this is lower
than a certain tolerance level. "
"Binary floating point and .NET"
http://www.yoda.arachsys.com/csharp/floatingpoint.html
I think this should be a very important aspect of floating point.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.
- References:
- Double comparisons for equality
- From: Jason Frank
- Re: Double comparisons for equality
- From: Jon Skeet [C# MVP]
- Re: Double comparisons for equality
- From: Jason Frank
- Re: Double comparisons for equality
- From: "Jeffrey Tan[MSFT]"
- Re: Double comparisons for equality
- From: Jason Frank
- Double comparisons for equality
- Prev by Date: Re: Double comparisons for equality
- Next by Date: Re: FIFO mutex
- Previous by thread: Re: Double comparisons for equality
- Next by thread: ILMerge and Linking the Runtime
- Index(es):
Relevant Pages
|
Loading