Re: String representation of Double.POSITIVE_INFINITY
Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Nov 25, 2010; 7:39pm
URL: http://imagej.273.s1.nabble.com/String-representation-of-Double-POSITIVE-INFINITY-tp3686354p3686355.html
On Nov 25, 2010, at 6:18 AM, Michael Doube wrote:
> Dear all,
>
> I'm writing a small helper method to validate text input in a
> GenericDialog. My idea is to return false if something other than a
> valid number is entered into a numeric field, so then the
> dialogItemChanged method will also return false, which greys out the OK
> button and prevents the plugin from running. This was all very easy
> until I tested a dialog that normally has a numeric field whose default
> value is Double.POSITIVE_INFINITY.
>
> This is represented by the '∞' character in the dialog, due to IJ.d2s:
>
> <---
> if (Double.isInfinite(n))
> return ""+n;
> - --->
>
> If I try to construct a Double("∞") or run parseDouble("∞") I get a
> NumberFormatException. Double(Double.POSITIVE_INFINITY).toString()
> returns "Infinity".
>
> It seems like GenericDialog handles this by looking the value up using
> Interpreter, but I get lost about here.
>
> At the moment, it looks like the most sensible thing to do is a
> String.replace("∞", "Infinity") before using any of Double's methods.
>
> Any suggestions on how to handle this better would be appreciated.
>
> Michael
This bug is fixed in the 1.44k16 daily build.
-wayne