Groups > BEA > JRockit > Double.isNaN not working properly




Double.isNaN not working properly

Double.isNaN not working properly
Mon, 5 May 2008 15:48:23 -0700
Hi,
    I am hitting an intermittent problem with the Double.isNaN method in
jrockit.  Occasionally, Double.isNaN is not returning true for what I believe is
a NaN.
    In the following code, I check whether the string value is NaN after the
numerical NaN check:

public void add(double d) {
  if (Double.isNaN(d))
        return;

  if ("NaN".equals(d + "")) 
       _log.error("NaN is slipping through");
}

And I am seeing the logging that verifies that the numerical NaN check is
failing.  But this problem only surfaces VERY RARELY in long application runs
and is non-deterministic.   I can run the same process again with the same
inputs and get different results.  However, when I start seeing the error
logging, I see it a lot which leads me to believe that some state is changing in
the JVM.  

I traced the string value to the native
sun.misc.FloatingDecimal(d).toJavaFormatString() method which seems to correctly
think the double value is a NaN while Double.isNaN does not.  

I tried running with -Xstrictfp, which fixed a NaN bug related to Math.max()
here:
http://forums.bea.com/thread.jspa?threadID=5700000142

but I still get the problem.  

Is the jrockit source for Double.isNaN() available to the public? In sun's impl,
it simply uses d != d as a check and  I inspected the src.zip that came with our
linux install and rt.jar in jre/lib/rt.jar but it appears to be the same code as
the sun implementation of Double.isNaN.

If someone could point me to source code or some possible JVM state change that
would change the way Double.isNaN works, please let me know. 

I am running with:
BEA JRockit(R) (build R27.4.0-90-89592-1.5.0_12-20070928-1715-linux-x86_64,
compiled mode)

with JVM args:
-Xmx4096m -XgcPrio:throughput -enableassertions  -XstrictFP
-Djava.library.path=/usr/local/java/jrockit/jre/lib/amd64/jrockit:/usr/local/jav
a/jrockit/jre/lib/amd64:/usr/local/java/jrockit/lib/amd64

Much thanks,
Post Reply
about | contact