Re: Double comparison problem
From: chris (caj_at_cs.york.ac.uk)
Date: 01/19/05
- Next message: REH: "Re: Help with Koenig Lookup"
- Previous message: Karl Heinz Buchegger: "Re: Can't make a COM Object external"
- In reply to: Dietmar Kuehl: "Re: Double comparison problem"
- Next in thread: Howard: "Re: Double comparison problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 19 Jan 2005 14:48:13 +0000
Dietmar Kuehl wrote:
> 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'.
OK, I apologise, I was perhaps a little too strong :) There are cases
where == and != can be used safely as long as you stay within some
reasonably tight bounds, as long as are careful :) But like you say you
have to be careful, so I find it easier to scare people off using == and
!= altogether, because I've seen far, far more cases where they were
being used incorrectly, and only a handful where they were being used
correctly, and in those cases the people using them knew they were using
them correctly :)
The idea of using a long double to replace a long long wasn't one I'd
seen before, thats quite a neat idea (although once again requires being
reasonably careful).
Chris
- Next message: REH: "Re: Help with Koenig Lookup"
- Previous message: Karl Heinz Buchegger: "Re: Can't make a COM Object external"
- In reply to: Dietmar Kuehl: "Re: Double comparison problem"
- Next in thread: Howard: "Re: Double comparison problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|