You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-dev@jakarta.apache.org by Tom Rodriguez <Th...@sun.com> on 2002/12/07 03:30:22 UTC

[PATCH] small bug fix for ConstantPoolGen and NaN

ConstantPoolGen.lookupFloat and ConstantPoolGen.lookupDouble don't work 
correctly for NaN, since NaN != NaN.  Here's small fix for it which 
compares the canonical bit pattern of the double or float instead.

tom

Index: ConstantPoolGen.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-bcel/src/java/org/apache/bcel/generic/ConstantPoolGen.java,v
retrieving revision 1.3
diff -u -r1.3 ConstantPoolGen.java
--- ConstantPoolGen.java        11 Jul 2002 19:39:04 -0000      1.3
+++ ConstantPoolGen.java        7 Dec 2002 01:42:49 -0000
@@ -323,11 +323,12 @@
     * @return index on success, -1 otherwise
     */
    public int lookupFloat(float n) {
+    int bits = Float.floatToIntBits(n);
      for(int i=1; i < index; i++) {
        if(constants[i] instanceof ConstantFloat) {
         ConstantFloat c = (ConstantFloat)constants[i];

-       if(c.getBytes() == n)
+       if(Float.floatToIntBits(c.getBytes()) == bits)
           return i;
        }
      }
@@ -438,11 +439,12 @@
     * @return index on success, -1 otherwise
     */
    public int lookupDouble(double n) {
+    long bits = Double.doubleToLongBits(n);
      for(int i=1; i < index; i++) {
        if(constants[i] instanceof ConstantDouble) {
         ConstantDouble c = (ConstantDouble)constants[i];

-       if(c.getBytes() == n)
+       if(Double.doubleToLongBits(c.getBytes()) == bits)
           return i;
        }
      }


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>