Re: Comparing floating point values in Java
- From: "Daniel Pitts" <googlegroupie@xxxxxxxxxxxxx>
- Date: 30 Dec 2006 16:03:06 -0800
Eric Sosman wrote:
Philipp wrote:
[...]
I was calculating an array of float values from some user input. But
sometimes (rarely) the calculation cannot be done (this is correct
behavior).
I then want to mark these values by setting them to -1 and treat this
special case later on. So I later need to test for -1 in my array.
Perhaps you can avoid the entire issue by choosing a
different "distinguished value." Float.NaN, maybe, using
the Float.isNaN(float) method instead of an == test. (NaN
seems a more natural surrogate for "does not compute," too.)
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxx
Or even have a seperate boolean array to specify valid results.
Having a magic value isn't generally a good idea, although NaN would be
the way to go if you did.
.
- Follow-Ups:
- Re: Comparing floating point values in Java
- From: Patricia Shanahan
- Re: Comparing floating point values in Java
- References:
- Comparing floating point values in Java
- From: Philipp
- Re: Comparing floating point values in Java
- From: Arne Vajhøj
- Re: Comparing floating point values in Java
- From: Philipp
- Re: Comparing floating point values in Java
- From: Eric Sosman
- Comparing floating point values in Java
- Prev by Date: Re: Need a new access modifier?
- Next by Date: Re: Comparing floating point values in Java
- Previous by thread: Re: Comparing floating point values in Java
- Next by thread: Re: Comparing floating point values in Java
- Index(es):
Relevant Pages
|