ASF Bugzilla – Attachment 28880 Details for
Bug 53327
[PATCH] DoubleFormatUtil does not work with huge precision
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch for both class and test case (DoubleFormatUtil.java and DoubleFormatUtilTest.java)
DoubleFormatUtil-patch2.txt (text/plain), 2.58 KB, created by
Julien Aymé
on 2012-06-04 10:58:36 UTC
(
hide
)
Description:
patch for both class and test case (DoubleFormatUtil.java and DoubleFormatUtilTest.java)
Filename:
MIME Type:
Creator:
Julien Aymé
Created:
2012-06-04 10:58:36 UTC
Size:
2.58 KB
patch
obsolete
>Index: src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java >=================================================================== >--- src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java (revision 1345759) >+++ src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java (working copy) >@@ -347,8 +347,9 @@ > * @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 @@ > 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; >Index: test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java >=================================================================== >--- test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java (revision 1345759) >+++ test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java (working copy) >@@ -124,6 +124,21 @@ > 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 @@ > > 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();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 53327
:
28859
|
28860
| 28880 |
28891
|
28892