Re: Extremely wierd problem I just cannot explain...works in debug, does not work in release.
- From: Stephan Rose <kermos@xxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 06 Nov 2006 20:50:38 +0100
On 6 Nov 2006 09:21:50 -0800, "Bruce Wood" <brucewood@xxxxxxxxxx>
wrote:
I agree with Adam: comparing floats / doubles for equality is a big
no-no.
Furthermore, a float or double should be used to store _only_ measured
quantities for which the concept of error makes sense. For example, you
could use a float or double to store "35.1523mm of rain", because if
you you're going to compare that quantity to something else, a
statement like "within 0.00001mm of yesterday's rainfall" makes sense.
You should never use floats or doubles to represent quantities or
things where precise values matter. The classic example is using them
to store monetary values (a quick road to losing / gaining pennies here
and there). So, I have to wonder exactly what "address" is... I have
the sneaking suspicion that losing a digit on an "address" would be
disastrous....
In cases in which your application can't tolerate precision loss you
should use decimal. If the number of decimal places is fixed then you
may also be able to use int or long and just remember how many decimal
places there are.
Adam Clauss wrote:
float address = entry.Address;
address += (float)entry.Bit/10.0f;
if(addr == address)The thing that catches my eye is that you are testing
equality on floating point values. That is generally a big no no as
floating point values are typically NOT exact.
If you had a "logical" value of 10.0, it might actually come out to
10.0000000001 or somethign along that line. Thus the test for equality
would fail. The better way would be to substract the two and take the
Math.Abs() - see if that value is less than a certain 'tolerance' level
(aka: they are close enough that you know they are actually the same).
Ya know what guys, I didn't even think about that....
I am definitely going to check that tomorrow!
Thanks for the heads up!
--
Stephan
2003 Yamaha R6
kimi no koto omoidasu hi nante nai no wa
kimi no koto wasureta toki ga nai kara
.
- References:
- Extremely wierd problem I just cannot explain...works in debug, does not work in release.
- From: Stephan Rose
- Re: Extremely wierd problem I just cannot explain...works in debug, does not work in release.
- From: Stephan Rose
- Re: Extremely wierd problem I just cannot explain...works in debug, does not work in release.
- From: Adam Clauss
- Re: Extremely wierd problem I just cannot explain...works in debug, does not work in release.
- From: Bruce Wood
- Extremely wierd problem I just cannot explain...works in debug, does not work in release.
- Prev by Date: Re: BackgroundWorker who knows how the magic works?
- Next by Date: Re: Changing the start up form
- Previous by thread: Re: Extremely wierd problem I just cannot explain...works in debug, does not work in release.
- Next by thread: how to cast variables using letters
- Index(es):
Relevant Pages
|