You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ga...@apache.org on 2012/06/05 08:04:49 UTC

svn commit: r1346249 - in /xmlgraphics/commons/branches/commons-1_5rc1: src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java status.xml test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java

Author: gadams
Date: Tue Jun  5 06:04:48 2012
New Revision: 1346249

URL: http://svn.apache.org/viewvc?rev=1346249&view=rev
Log:
Merge from origin/trunk.

Modified:
    xmlgraphics/commons/branches/commons-1_5rc1/src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java
    xmlgraphics/commons/branches/commons-1_5rc1/status.xml
    xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java

Modified: xmlgraphics/commons/branches/commons-1_5rc1/src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/commons-1_5rc1/src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java?rev=1346249&r1=1346248&r2=1346249&view=diff
==============================================================================
--- xmlgraphics/commons/branches/commons-1_5rc1/src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java (original)
+++ xmlgraphics/commons/branches/commons-1_5rc1/src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java Tue Jun  5 06:04:48 2012
@@ -347,8 +347,9 @@ public final class DoubleFormatUtil {
      * @return true if the rounding will potentially use too many digits
      */
     private static boolean tooManyDigitsUsed(double source, int scale) {
-        // if scale >= 19, 10^19 > Long.MAX_VALUE
-        return scale >= 19 || getExponant(source) + scale >= 14;
+        // if scale >= 308, 10^308 ~= Infinity
+        double decExp = Math.log10(source);
+        return scale >= 308 || decExp + scale >= 14.5;
     }
 
     /**
@@ -363,7 +364,8 @@ public final class DoubleFormatUtil {
         source = Math.abs(source);
         long intPart = (long) Math.floor(source);
         double fracPart = (source - intPart) * tenPowDouble(scale);
-        double range = .001;
+        double decExp = Math.log10(source);
+        double range = decExp + scale >= 12 ? .1 : .001;
         double distanceToRound1 = Math.abs(fracPart - Math.floor(fracPart));
         double distanceToRound2 = Math.abs(fracPart - Math.floor(fracPart) - 0.5);
         return distanceToRound1 <= range || distanceToRound2 <= range;

Modified: xmlgraphics/commons/branches/commons-1_5rc1/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/commons-1_5rc1/status.xml?rev=1346249&r1=1346248&r2=1346249&view=diff
==============================================================================
--- xmlgraphics/commons/branches/commons-1_5rc1/status.xml (original)
+++ xmlgraphics/commons/branches/commons-1_5rc1/status.xml Tue Jun  5 06:04:48 2012
@@ -38,6 +38,9 @@
   </contexts>
   <changes>
     <release version="1.5rc1" date="3 June 2012">
+      <action context="Code" dev="GA" type="update" fixes-bug="53327" due-to="Julien Aymé">
+        Fix determination of use of precise vs fast formatting in order to fix regression with value 5.22534294505995E-4, decimals: 17, precision: 17.
+      </action>
       <action context="Code" dev="GA" type="fix" fixes-bug="53352" importance="high">
         Upgrade to checkstyle-5.5 and ensure no warnings.
       </action>

Modified: xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java?rev=1346249&r1=1346248&r2=1346249&view=diff
==============================================================================
--- xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java (original)
+++ xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java Tue Jun  5 06:04:48 2012
@@ -124,6 +124,21 @@ public class DoubleFormatUtilTest extend
         expected = "0.00585938";
         actual = format(value, 8, 8);
         assertEquals(value, 8, 8, expected, actual);
+
+        value = 5.22534294505995E-4;
+        expected = "0.000522534294506";
+        actual = format(value, 17, 17);
+        assertEquals(value, 17, 17, expected, actual);
+
+        value = 4.9E-324;
+        expected = "0";
+        actual = format(value, 309, 309);
+        assertEquals(value, 309, 309, expected, actual);
+
+        value = 7.003868765287485E-280;
+        expected = refFormat(value, 294, 294);
+        actual = format(value, 294, 294);
+        assertEquals(value, 294, 294, expected, actual);
     }
 
     public void testLimits() {
@@ -412,8 +427,8 @@ public class DoubleFormatUtilTest extend
 
         double value, highValue, lowValue;
         long start = System.currentTimeMillis();
-        int nbTest = 100000;
-        int maxDecimals = 10;
+        int nbTest = 1000000;
+        int maxDecimals = 16;
 
         r.setSeed(seed);
         start = System.currentTimeMillis();



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org