Created attachment 28859 [details] Patch for the test case, which shows the issue The new DoubleFormatUtil class fails to format correctly doubles near Double.MIN_VALUE (0 <= value <= 1e-300) with precision between 300 and 340. I fixed the DoubleFormatUtil class and added a test case which shows the issue.
Created attachment 28860 [details] The patched DoubleFormatUtil
applied at http://svn.apache.org/viewvc?rev=1345315&view=rev thanks julien, please review and close if satisfied
Thanks Glenn for applying the patch, everything seems fine after review. I'm closing the bug.
(In reply to comment #3) > Thanks Glenn for applying the patch, everything seems fine after review. > I'm closing the bug. I encountered a failure when running junit on XGC today as follows: Testcase: testAllDoubleRanges took 4.477 sec FAILED value: 5.22534294505995E-4, decimals: 17, precision: 17 expected:<0.00052253429450[6]> but was:<0.00052253429450[599]> junit.framework.ComparisonFailure: value: 5.22534294505995E-4, decimals: 17, precision: 17 expected:<0.00052253429450[6]> but was:<0.00052253429450[599]> at org.apache.xmlgraphics.util.DoubleFormatUtilTest.assertEquals(DoubleFormatUtilTest.java:223) at org.apache.xmlgraphics.util.DoubleFormatUtilTest.testAllDoubleRanges(DoubleFormatUtilTest.java:531) However, on a re-attempt, it did not fail. Perhaps this is because you use random numbers in your test data.
I'll investigate on this particular value + precision on monday.
OK, I found the issue: in certain cases, the method "tooCloseTooRound" should return true so that the "formatPrecise" method is used instead of the "formatFast" method. So I tweaked the "tooManyDigitsUsed" and "tooCloseTooRound" methods a bit, so that they perform better. Patch will follow.
Created attachment 28880 [details] patch for both class and test case (DoubleFormatUtil.java and DoubleFormatUtilTest.java) Enhanced DoubleFormatUtil.tooCloseTooRound + DoubleFormatUtil.tooManyDigitsUsed
The aim of these two methods ("tooManyDigitsUsed" and "tooCloseTooRound") is to force to use formatPrecise whenever we're not sure that formatFast will produce the right result, but only when formatFast fails, since formatPrecise is much slower (4 times) than formatFast.
patch applied at http://svn.apache.org/viewvc?rev=1346092&view=rev thanks julien, please verify and close
Verified, everything seems OK. Closing bug.
I found the last (I hope) really rare bugs: - The first one is due to long <-> double conversion error in DoubleFormatUtil.format private method - The second is due to a rounding error in double division in DoubleFormatUtil.isRoundedToZero private method when rounding an exact value 5e-N value for certain value of N (when scale = N-1). Patch for test case and class will follow. Hopefully I won't find any bug concerning this class anymore.
Created attachment 28891 [details] Patch n.2 for the test case
Created attachment 28892 [details] Patch n.2 for DoubleFormatUtil class
apply patch n.2 at http://svn.apache.org/viewvc?rev=1346428&view=rev thanks julien, please review and close
At last, everything seems OK ! Thank you again Glenn.