harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r397091 - in /incubator/harmony/enhanced/classlib/trunk/modules/math: make/common/build.xml src/main/java/java/math/BigDecimal.java src/main/java/java/math/BigInteger.java src/test/java/tests/api/java/math/BigDecimalTest.java
Date Wed, 26 Apr 2006 05:05:30 GMT
Author: mloenko
Date: Tue Apr 25 22:05:28 2006
New Revision: 397091

URL: http://svn.apache.org/viewcvs?rev=397091&view=rev
Log:
final fix for HARMONY-319
BigDecimal and Biginteger test failures should be fixed

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/math/make/common/build.xml
    incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigDecimal.java
    incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigInteger.java
    incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/make/common/build.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/math/make/common/build.xml?rev=397091&r1=397090&r2=397091&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/make/common/build.xml (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/make/common/build.xml Tue Apr 25
22:05:28 2006
@@ -96,10 +96,6 @@
             <batchtest todir="${hy.tests.reports}" haltonfailure="no">
                 <fileset dir="${hy.math.src.test.java}">
                     <include name="**/*Test.java" />
-                    <!-- This test seems to loop -->
-                    <exclude name="**/api/java/math/BigDecimalTest.java" />
-                    <!-- This test fails -->
-                    <exclude name="**/api/java/math/BigIntegerTest.java" />
                 </fileset>
             </batchtest>
         </junit>

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigDecimal.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigDecimal.java?rev=397091&r1=397090&r2=397091&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigDecimal.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigDecimal.java
Tue Apr 25 22:05:28 2006
@@ -266,6 +266,10 @@
             }
             if (symbol == '+') {
                 count++;
+                symbol = in[count];
+                if(symbol == '-') {
+                    throw new NumberFormatException("exponent is not signed integer");
+                }
             }
             exponent = new String(in, count, endIndex - count + 1);
             int exp = 0;
@@ -408,6 +412,10 @@
         int strLen = value.length();
         String unscaled;
         String exponent;
+        
+        if(strLen == 0) {
+            throw new NumberFormatException("empty string");
+        }
         char symbol = value.charAt(0);
         int startPoint = symbol == '+' ? 1 : 0;
         
@@ -442,6 +450,10 @@
             }
             if (symbol == '+') {
                 count++;
+                symbol = value.charAt(count);
+                if(symbol == '-') {
+                    throw new NumberFormatException("exponent is not signed integer");
+                }
             }
             exponent = value.substring(count, strLen);
             int exp = 0;
@@ -1323,11 +1335,11 @@
         boolean negNumber = intVal.signum() < 0;
         int startPoint = negNumber ? 2 : 1;
         int endPoint = intString.length();
-        int exponent = -scale + intString.length() - (negNumber ? 2 : 1);
+        int exponent = -scale + intString.length() - startPoint;
         StringBuffer result = new StringBuffer(intString);
         if (scale > 0 && exponent >= -6) {
             if (exponent >= 0) {
-                result.insert(exponent + (negNumber ? 2 : 1), '.');
+                result.insert(exponent + startPoint, '.');
             } else {
                 char zeros[] = new char[-exponent + 1];
                 zeros[0] = '0';
@@ -1384,12 +1396,12 @@
         boolean negNumber = intVal.signum() < 0;
         int startPoint = negNumber ? 2 : 1;
         int endPoint = intString.length();
-        int dotPosition = -scale + intString.length() - (negNumber ? 2 : 1);
+        int dotPosition = -scale + intString.length() - startPoint;
         StringBuffer result = new StringBuffer(intString);
         char zeros[];
         if (scale > 0) {
             if (dotPosition >= 0) {
-                result.insert(dotPosition + (negNumber ? 2 : 1), '.');
+                result.insert(dotPosition + startPoint, '.');
             } else {
                 zeros = new char[-dotPosition + 1];
                 zeros[0] = '0';

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigInteger.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigInteger.java?rev=397091&r1=397090&r2=397091&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigInteger.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigInteger.java
Tue Apr 25 22:05:28 2006
@@ -67,26 +67,6 @@
     /**
      * @com.intel.drl.spec_ref
      */
-    private int bitCount = -1;
-    
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    private int bitLength = -1;
-    
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    private int lowestSetBit = -2;
-    
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    private int firstNonzeroByteNum = -2;
-    
-    /**
-     * @com.intel.drl.spec_ref
-     */
     private byte[] magnitude;
     
     /**
@@ -423,18 +403,6 @@
     }
 
     /**
-     * Counts the bit length of an unsigned int value 
-     */
-    private static int getBitLength(int value) {
-        int bitLen = 32;
-        int topOne = 0x80000000;
-        while (((value & topOne) == 0) && bitLen-- > 0) {
-            topOne >>>= 1;
-        }
-        return bitLen;
-    }
-
-    /**
      * Gets the number of radix-based digits that fits in an integer
      * @param radix the radix of the numerical system
      * @return the number of digits 
@@ -730,7 +698,7 @@
         if (numberBitLength < 0) {
             throw new IllegalArgumentException("negative bit length");
         }
-        boolean stripLeadingZeroes = true;
+        boolean stripLeadingZeroes = numberBitLength > 0;
         constructRandomly(numberBitLength, rand, stripLeadingZeroes);
     }
 
@@ -1173,6 +1141,9 @@
      */
     public int compareTo(BigInteger that) {
         if (this.sign == that.sign) {
+           	if(this.sign == 0) {
+           		return 0;
+           	}
             int compareResult = compareMagnitude(this.digits,
                     this.numberLength, that.digits, that.numberLength);
             if (this.sign == 1) {
@@ -1194,7 +1165,7 @@
      */
     private void constructRandomly(int numberBitLength, Random rand,
             boolean stripLeadingZeroes) {
-        sign = 1;
+    	sign = numberBitLength == 0 ? 0 : 1;
         int numberOfDigits = numberBitLength >> 5;
         int numberOfTopBits = numberBitLength & 31;
         if (numberOfTopBits > 0) {
@@ -1207,7 +1178,6 @@
         }
         if (numberOfTopBits > 0) {
             digits[numberLength - 1] &= ((1 << numberOfTopBits) - 1);
-            int q = numberLength - 1;
         }
         if (stripLeadingZeroes) {
             cutOffLeadingZeroes();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java?rev=397091&r1=397090&r2=397091&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java
Tue Apr 25 22:05:28 2006
@@ -135,6 +135,23 @@
 		} catch (NumberFormatException e) {
 		}
 	}
+    
+    /**
+     * @tests java.math.BigDecimal#BigDecimal(char[])
+     */
+    public void test_constructor_CC_plus_minus_exp() {
+        try {
+            new BigDecimal("+35e+-2".toCharArray());          
+            fail("NumberFormatException expected");
+        } catch (NumberFormatException e) {
+        }
+        
+        try {
+            new BigDecimal("-35e-+2".toCharArray());          
+            fail("NumberFormatException expected");
+        } catch (NumberFormatException e) {
+        }
+    }
 
 	/**
 	 * @tests java.math.BigDecimal#abs()



Mime
View raw message