harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r793829 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/org/apache/harmony/luni/util/FloatingPointParser.java test/api/common/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
Date Tue, 14 Jul 2009 09:32:34 GMT
Author: tellison
Date: Tue Jul 14 09:32:33 2009
New Revision: 793829

URL: http://svn.apache.org/viewvc?rev=793829&view=rev
Log:
Apply fix for HARMONY-329 ([classlib][luni] Endless loop when using Double.parseDouble(String)
with certain types of value)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/DoubleTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java?rev=793829&r1=793828&r2=793829&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
Tue Jul 14 09:32:33 2009
@@ -172,6 +172,17 @@
 			s = s.substring(start, end);
 		}
 
+        // Trim the length of very small numbers, natives can only handle down
+        // to E-309
+        final int APPROX_MIN_MAGNITUDE = -359;
+        final int MAX_DIGITS = 52;
+        length = s.length();
+        if (length > MAX_DIGITS && e < APPROX_MIN_MAGNITUDE) {
+            int d = Math.min(APPROX_MIN_MAGNITUDE - e, length - 1);
+            s = s.substring(0, length - d);
+            e += d;
+        }
+
 		return new StringExponentPair(s, e, negative);
 	}
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/DoubleTest.java?rev=793829&r1=793828&r2=793829&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
Tue Jul 14 09:32:33 2009
@@ -219,13 +219,17 @@
         assertEquals("Created incorrect double", 39089.88888888888888888888888888888888,
d
                 .doubleValue(), 0D);
 
-        // REGRESSION for HARMONY-489
+        // Regression test for HARMONY-489
         try {
             d = new Double("1E+-20");
             fail("new Double(\"1E+-20\") should throw exception");
         } catch (NumberFormatException e) {
             // expected
         }
+        
+        // Regression test for HARMONY-329
+        d = Double.parseDouble("-1.233999999999999965116738099630936817275852021384209929081813042837802886790127428328465579708849276001782791006814286802871737087810957327493372866733334925806221045495205250590286471187577636646208155890426896101636282423463443661040209738873506655844025580428394216030152374941053494694642722606658935546875E-112");
+        assertEquals("Failed to parse long string", -1.234E-112D, d.doubleValue(), 0D);
     }
 
     /**



Mime
View raw message