Re: Double comparison problem

From: Dietmar Kuehl (dietmar_kuehl_at_yahoo.com)
Date: 01/19/05


Date: 19 Jan 2005 05:44:46 -0800

chris wrote:
> There are two groups of people in this world.
>
> 1) Those who don't fully understand all of the details about
performing
> == and != on floating points values. They should never use == or !=
on
> floating point values (not being mean or anything, they just
shouldn't).
>
> 2) Those who do understand all the details about performing == and !=
on
> floating point values. They don't use == and !=, so don't have to be
> told not to :)

I'd say you fall into the first group! After all, comparing floating
point values representing reasonably sized integers is perfectly
valid even using '==' or '!=': you can use floating point values as a
form of bigger integer. You just have to take care of the values
staying in a certain range. Actually, you can also do exact
computations
for other values, i.e. those which can represented exactly. The only
thing to note is that the set of useful values is not closed over the
operations and you need to realize when the result of the operation is
of different kind (e.g. when addition or multiplication overflows,
substraction cancels leading bits, and division is only valid for
certain value). Sure enough, for most of my uses I don't play tricks
with floating point values but it is still possible and if you e.g.
need a 64 bit integer on a platform not supporting some form of
"long long" it can be an appropriate choice to use a 'long double'.

--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting


Relevant Pages

  • Re: Double comparison problem
    ... Dietmar Kuehl wrote: ... > chris wrote: ... After all, comparing floating ... as long as are careful:) But like you say you ...
    (comp.lang.cpp)
  • Re: Error in precision with number operations
    ... for really in-depth info on floating point arithmetic and rounding issues. ... Chris. ... I´ve a problem with some number operations in VBScript:: ...
    (microsoft.public.scripting.vbscript)
  • INF & IND errors
    ... How do I update or delete a record with this floating point error in X ... what the heck causes it? ... Chris ... Prev by Date: ...
    (microsoft.public.sqlserver.odbc)
  • Re: standard min/max function
    ... Chris wrote: ... I am looking for a floating point version. ... And if you were after a C answer, check if your compiler has the function ... a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Arithmetic oddity
    ... That will be due to rounding errors in performing the ... sequence of floating point operations. ...
    (comp.lang.ruby)