Re: Funny Comparison with Float
Keith Hill <[email protected]> Fri, 7 Mar 2008 09:55:12 -0700
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <85C056DDAA11E24991A029636B33BBA801135321@cos-us-mb02.cos.agilent.com> |
> -----Original Message----- > From: Brady Kelly [mailto:[email protected]] > Sent: Thursday, March 06, 2008 7:20 AM > Subject: Re: Funny Comparison with Float >=20 > > BTW, you never should check floats or doubles with an equal sign. > > Always use a greater or less sign. > > > > // Ryan >=20 > Like 'version > 1 && version < 1.11' ? >=20 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. -- Keith =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D This list is hosted by DevelopMentor=AE http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com