Re: Comparing floating point values in Java



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
.



Relevant Pages

  • [OT] Re: model implementation
    ... I want to know the very basics of model ... What I did was create a two-dimensional array of double values, ... The total length of the simulation was a value I let the user decide, ... calculating each level's new content based entirely on the values ...
    (comp.lang.cpp)
  • Re: Date and Time Formula
    ... on this array to extarct the MIN value for that date. ... Could you explain how the formula is calculating e.g. how ... >> clock) I want to be able to do a formula that says; ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Comparing floating point values in Java
    ... I was calculating an array of float values from some user input. ... Having a magic value isn't generally a good idea, although NaN would be ... Using any magic value, including NaN, has the risk that a bug elsewhere ...
    (comp.lang.java.programmer)
  • Re: Comparing floating point values in Java
    ... I was calculating an array of float values from some user input. ... Having a magic value isn't generally a good idea, although NaN would be ... Using any magic value, including NaN, has the risk that a bug elsewhere ...
    (comp.lang.java.programmer)
  • Assigning multiple datatypes to array
    ... gotta push it to an array for calculating certain columns, then spit it to a ... How do I store all the different datatypes in a multidimensional array, ... I'm doing this becuase the Stored Procedure ...
    (microsoft.public.dotnet.languages.csharp)