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/04 21:04:35 UTC
svn commit: r1346092 - in /xmlgraphics/commons/trunk:
src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java status.xml
test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java
Author: gadams
Date: Mon Jun 4 19:04:34 2012
New Revision: 1346092
URL: http://svn.apache.org/viewvc?rev=1346092&view=rev
Log:
Bugzilla #53327: Fix determination of use of precise vs fast formatting in order to fix regression with value 5.22534294505995E-4, decimals: 17, precision: 17.
Modified:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java
xmlgraphics/commons/trunk/status.xml
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java?rev=1346092&r1=1346091&r2=1346092&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java Mon Jun 4 19:04:34 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/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/status.xml?rev=1346092&r1=1346091&r2=1346092&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/status.xml (original)
+++ xmlgraphics/commons/trunk/status.xml Mon Jun 4 19:04:34 2012
@@ -41,6 +41,9 @@
</contexts>
<changes>
<release version="Trunk" date="n/a">
+ <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">
Upgrade to checkstyle-5.5 and ensure no warnings.
</action>
Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java?rev=1346092&r1=1346091&r2=1346092&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java Mon Jun 4 19:04:34 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