GWT apparent inconsistence in JRE emulation

139 views
Skip to first unread message

santiago...@gmail.com

unread,
Aug 20, 2006, 2:45:24 AM8/20/06
to Google Web Toolkit
Can anybody explain to me why the GWT subset of the JRE contains
methods Double.isNAN() and Float.isNAN() without including the
correspondig fields Double.NAN and Float.NAN ? It is probably an idiot
question.

Fushion

unread,
Aug 20, 2006, 2:17:09 PM8/20/06
to Google Web Toolkit
This is because the JRE emulation converts these functions to their
javascript equivalents.
See the implementation of the emul package:

public boolean isNaN() {
return isNaN(fValue);
}

public static native boolean isNaN(double x) /*-{
return isNaN(x);
}-*/;

public boolean isInfinite() {
return isInfinite(fValue);
}

public static native boolean isInfinite(double x) /*-{
return !isFinite(x);
}-*/;

santiago...@gmail.com

unread,
Aug 20, 2006, 4:00:24 PM8/20/06
to Google Web Toolkit
Thanks. But I do not really understand whether or not I am able to use
something similar to Double.NAN or not . Is there an equivalent in
javascript to the Double.NAN that there is in java? If not how come
there is a method "isNaN(double x)" and no way in which this argument
"double x" can be NAN?

I want to use a couple of classes for doing numeric mathematics using
arrays ,which I had programmed before, which returned Double.NAN in
cases in which they were forced to do a division by zero or something
which was not defined, or even in cases in which a maximum number of
iterations had been reached. Double.NAN was returned because the
language demands that once set, there is only one return type for a
method.
This was my way of bypassing exception handling, which is a concept
endemic to programming and language-dependednt. I suppose so are
"fields", so if you have any ideas on how to fix this I would be very
grateful.

Vivian Li

unread,
Aug 21, 2006, 2:49:47 AM8/21/06
to Google-We...@googlegroups.com

Hi Santiago,
  One workaround is to create a constant somewhere on a utility class, like on NumericUtils add a

  public static final Double NaN = new Double(0.0d/0.0d);

0.0/0.0 evaluates to NaN in both JavaScript and Java.

-Vivian






Reply all
Reply to author
Forward
0 new messages