Re: Funny Comparison with Float

Peter Ritchie <[email protected]> Fri, 7 Mar 2008 11:55:34 -0500
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <LISTSERV%[email protected]>
If only the framework contained useful[1] values for Epsilon.

[1] https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?
FeedbackID=93726&wa=wsignin1.0

On Fri, 7 Mar 2008 09:55:12 -0700, Keith Hill <[email protected]>
wrote:

>> -----Original Message-----
>> From: Brady Kelly [mailto:[email protected]]
>> Sent: Thursday, March 06, 2008 7:20 AM
>> Subject: Re: Funny Comparison with Float
>>
>> > BTW, you never should check floats or doubles with an equal sign.
>> > Always use a greater or less sign.
>> >
>> > // Ryan
>>
>> Like 'version > 1 && version < 1.11' ?
>>
>
>It is a bit more complicated than that.  A robust "AlmostEquals" routine
would handle not only epsilon (I'd use something like 1E-5) but also Inf,
NaN and overflow when adding and/or subtracting the two values to compare
to epsilon).  You might check around for a math library that does this.

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com