commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luc Maisonobe <>
Subject Re: [math] Shoud OpenIntToDoubleHashMap get return NaN instead of 0 for key not found?
Date Fri, 02 Jan 2009 15:53:25 GMT
Phil Steitz a écrit :
> I am still working through this class and the sparse matrix class that
> it was extracted from (thanks, Ismael and Sugit!), so I am not sure if
> changing this would cause problems, but the current setup (returning 0
> for missing keys) limits usefulness of this class.   I see how this is
> convenient for sparse matrices; but I would see NaN as a more natural
> return value for non-existent keys in the general case.  Alternatively, 
> I guess we could add another method get(int key, double missingReturn).
> Thoughts?

I had exactly the same thought while extracting the class.
I also prefer to use Double.NaN for numbers that have never been
initialized explicitly, but I also understand 0 is more logical in the
special case of sparse matrices.

What about having a configurable value for missing entries ? It should
probably be configured at construction time (with a default value to
Double.NaN if not specified) and never changed afterwards. In the case
of sparse matrices, we should configure this value to 0.0.


> Phil
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message