harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r470833 - in /incubator/harmony/enhanced/classlib/trunk/modules/math/src: main/java/java/math/Logical.java test/java/org/apache/harmony/tests/java/math/BigIntegerOrTest.java
Date Fri, 03 Nov 2006 14:27:11 GMT
Author: tellison
Date: Fri Nov  3 06:27:10 2006
New Revision: 470833

URL: http://svn.apache.org/viewvc?view=rev&rev=470833
Log:
Apply patch and regression test for HARMONY-1996 ([classlib][math]BigInteger bitwise operations
work incorrectly for negative values)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Logical.java
    incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOrTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Logical.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Logical.java?view=diff&rev=470833&r1=470832&r2=470833
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Logical.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Logical.java
Fri Nov  3 06:27:10 2006
@@ -532,6 +532,7 @@
         int iNeg = negative.getFirstNonzeroDigit();
         int iPos = positive.getFirstNonzeroDigit();
         int i;
+        int limit;
         
         // Look if the trailing zeros of the positive will "copy" all
         // the negative digits
@@ -544,19 +545,34 @@
         if (iNeg < iPos ) {
             // We know for sure that this will
             // be the first non zero digit in the result
-            // resDigits[first non zero] = - (-negative.digits[i])
-            i = iNeg;
+            for (i = iNeg; i < iPos; i++) {
             resDigits[i] = negative.digits[i];
+            }
         } else if (iPos < iNeg) {
             i = iPos;
             resDigits[i] = -positive.digits[i];
+            limit = Math.min(positive.numberLength, iNeg);
+            for(i++; i < limit; i++ ) {
+                resDigits[i] = ~positive.digits[i];
+            }
+            if (i != positive.numberLength) {               
+                resDigits[i] = ~(-negative.digits[i] | positive.digits[i]);             
  
+            } else{
+                  for (; i<iNeg; i++) {
+                      resDigits[i] = -1;
+                  }
+                  // resDigits[i] = ~(-negative.digits[i] | 0);
+                  resDigits[i] = negative.digits[i] - 1;
+            }
+            i++;
         } else {// iNeg == iPos
             // Applying two complement to negative and to result
             i = iPos;
             resDigits[i] = -(-negative.digits[i] | positive.digits[i]);
+            i++;
         }
-        int limit = Math.min(negative.numberLength, positive.numberLength);
-        for (i++ ; i < limit; i++) {
+        limit = Math.min(negative.numberLength, positive.numberLength);
+        for (; i < limit; i++) {
             // Applying two complement to negative and to result
             // resDigits[i] = ~(~negative.digits[i] | positive.digits[i] );
             resDigits[i] = negative.digits[i] & ~positive.digits[i];

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOrTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOrTest.java?view=diff&rev=470833&r1=470832&r2=470833
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOrTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOrTest.java
Fri Nov  3 06:27:10 2006
@@ -408,4 +408,13 @@
         }
         assertEquals("incorrect sign", -1, result.signum());
     }
+    
+    public void testRegression() {
+        // Regression test for HARMONY-1996
+        BigInteger x = new BigInteger("-1023");
+        BigInteger r1 = x.and((BigInteger.ZERO.not()).shiftLeft(32));
+        BigInteger r3 = x.and((BigInteger.ZERO.not().shiftLeft(32) ).not());
+        BigInteger result = r1.or(r3);
+        assertEquals(x, result);
+    } 
 }



Mime
View raw message