Index: test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java =================================================================== --- test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java (revision 1344130) +++ test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java (working copy) @@ -260,6 +260,9 @@ * whereas DecimalFormat may have some formating errors regarding the last digit. */ private String refFormat(double value, int decimals, int precision) { + if (Double.isNaN(value) || Double.isInfinite(value)) { + return Double.toString(value); + } buf.setLength(0); BigDecimal bg = new BigDecimal(Double.toString(value)); int scale = Math.abs(value) < 1.0 ? precision : decimals; @@ -515,4 +518,18 @@ long toStringDuration = System.currentTimeMillis() - start; System.out.println("toString duration: " + toStringDuration + "ms to format " + (3 * nbTest) + " doubles"); } + + public void testAllDoubleRanges() { + Random r = new Random(); + double value; + String expected, actual; + for (int i = -330; i <= 315; i++) { + value = r.nextDouble() * Math.pow(10.0, i); + for (int scale = 1; scale <= 350; scale++) { + expected = refFormat(value, scale, scale); + actual = format(value, scale, scale); + assertEquals(value, scale, scale, expected, actual); + } + } + } }