harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r578087 - in /harmony/enhanced/classlib/trunk/modules/nio/src: main/java/java/nio/ test/java/common/org/apache/harmony/nio/tests/java/nio/
Date Fri, 21 Sep 2007 12:55:14 GMT
Author: tellison
Date: Fri Sep 21 05:55:14 2007
New Revision: 578087

URL: http://svn.apache.org/viewvc?rev=578087&view=rev
Log:
Fix NIO buffers to compare correctly when containing NaN's.

Modified:
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatBuffer.java
    harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
    harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java?rev=578087&r1=578086&r2=578087&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java Fri
Sep 21 05:55:14 2007
@@ -181,17 +181,19 @@
 				: otherBuffer.remaining();
 		int thisPos = position;
 		int otherPos = otherBuffer.position;
-		double thisByte, otherByte;
+		double thisDouble, otherDouble;
 		while (compareRemaining > 0) {
-			thisByte = get(thisPos);
-			otherByte = otherBuffer.get(otherPos);
-			if (thisByte != otherByte) {
-				return thisByte < otherByte ? -1 : 1;
-			}
-			thisPos++;
-			otherPos++;
-			compareRemaining--;
-		}
+            thisDouble = get(thisPos);
+            otherDouble = otherBuffer.get(otherPos);
+            // checks for double and NaN inequality
+            if ((thisDouble != otherDouble)
+                    && ((thisDouble == thisDouble) || (otherDouble == otherDouble)))
{
+                return thisDouble < otherDouble ? -1 : 1;
+            }
+            thisPos++;
+            otherPos++;
+            compareRemaining--;
+        }
 		return remaining() - otherBuffer.remaining();
 	}
 

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatBuffer.java?rev=578087&r1=578086&r2=578087&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatBuffer.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatBuffer.java Fri
Sep 21 05:55:14 2007
@@ -183,12 +183,14 @@
 				: otherBuffer.remaining();
 		int thisPos = position;
 		int otherPos = otherBuffer.position;
-		float thisByte, otherByte;
+		float thisFloat, otherFloat;
 		while (compareRemaining > 0) {
-			thisByte = get(thisPos);
-			otherByte = otherBuffer.get(otherPos);
-			if (thisByte != otherByte) {
-				return thisByte < otherByte ? -1 : 1;
+			thisFloat = get(thisPos);
+			otherFloat = otherBuffer.get(otherPos);
+            // checks for float and NaN inequality
+            if ((thisFloat != otherFloat)
+                    && ((thisFloat == thisFloat) || (otherFloat == otherFloat)))
{
+				return thisFloat < otherFloat ? -1 : 1;
 			}
 			thisPos++;
 			otherPos++;

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java?rev=578087&r1=578086&r2=578087&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
Fri Sep 21 05:55:14 2007
@@ -195,6 +195,17 @@
         other.limit(5);
         assertTrue(buf.compareTo(other) > 0);
         assertTrue(other.compareTo(buf) < 0);
+
+        DoubleBuffer dbuffer1 = DoubleBuffer.wrap(new double[] { Double.NaN });
+        DoubleBuffer dbuffer2 = DoubleBuffer.wrap(new double[] { Double.NaN });
+        DoubleBuffer dbuffer3 = DoubleBuffer.wrap(new double[] { 42d });
+
+        assertEquals("Failed equal comparison with NaN entry", 0, dbuffer1
+                .compareTo(dbuffer2));
+        assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer3
+                .compareTo(dbuffer1));
+        assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer1
+                .compareTo(dbuffer3));
     }
 
     public void testDuplicate() {

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java?rev=578087&r1=578086&r2=578087&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
Fri Sep 21 05:55:14 2007
@@ -20,6 +20,7 @@
 import java.nio.BufferOverflowException;
 import java.nio.BufferUnderflowException;
 import java.nio.ByteOrder;
+import java.nio.DoubleBuffer;
 import java.nio.FloatBuffer;
 import java.nio.InvalidMarkException;
 
@@ -184,6 +185,18 @@
         other.limit(5);
         assertTrue(buf.compareTo(other) > 0);
         assertTrue(other.compareTo(buf) < 0);
+        
+        FloatBuffer fbuffer1 = FloatBuffer.wrap(new float[] { Float.NaN });
+        FloatBuffer fbuffer2 = FloatBuffer.wrap(new float[] { Float.NaN });
+        FloatBuffer fbuffer3 = FloatBuffer.wrap(new float[] { 42f });
+
+        assertEquals("Failed equal comparison with NaN entry", 0, fbuffer1
+                .compareTo(fbuffer2));
+        assertEquals("Failed greater than comparison with NaN entry", 1, fbuffer3
+                .compareTo(fbuffer1));
+        assertEquals("Failed greater than comparison with NaN entry", 1, fbuffer1
+                .compareTo(fbuffer3));
+
     }
 
     public void testDuplicate() {



Mime
View raw message