View | Details | Raw Unified | Return to bug 53327
Collapse All | Expand All

(-)src/java/org/apache/xmlgraphics/util/DoubleFormatUtil.java (-3 / +5 lines)
Lines 347-354 Link Here
347
     * @return true if the rounding will potentially use too many digits
347
     * @return true if the rounding will potentially use too many digits
348
     */
348
     */
349
    private static boolean tooManyDigitsUsed(double source, int scale) {
349
    private static boolean tooManyDigitsUsed(double source, int scale) {
350
        // if scale >= 19, 10^19 > Long.MAX_VALUE
350
//      // if scale >= 308, 10^308 ~= Infinity
351
        return scale >= 19 || getExponant(source) + scale >= 14;
351
        double decExp = Math.log10(source);
352
        return scale >= 308 || decExp + scale >= 14.5;
352
    }
353
    }
353
354
354
    /**
355
    /**
Lines 363-369 Link Here
363
        source = Math.abs(source);
364
        source = Math.abs(source);
364
        long intPart = (long) Math.floor(source);
365
        long intPart = (long) Math.floor(source);
365
        double fracPart = (source - intPart) * tenPowDouble(scale);
366
        double fracPart = (source - intPart) * tenPowDouble(scale);
366
        double range = .001;
367
        double decExp = Math.log10(source);
368
        double range = decExp + scale >= 12 ? .1 : .001;
367
        double distanceToRound1 = Math.abs(fracPart - Math.floor(fracPart));
369
        double distanceToRound1 = Math.abs(fracPart - Math.floor(fracPart));
368
        double distanceToRound2 = Math.abs(fracPart - Math.floor(fracPart) - 0.5);
370
        double distanceToRound2 = Math.abs(fracPart - Math.floor(fracPart) - 0.5);
369
        return distanceToRound1 <= range || distanceToRound2 <= range;
371
        return distanceToRound1 <= range || distanceToRound2 <= range;
(-)test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java (-2 / +17 lines)
Lines 124-129 Link Here
124
        expected = "0.00585938";
124
        expected = "0.00585938";
125
        actual = format(value, 8, 8);
125
        actual = format(value, 8, 8);
126
        assertEquals(value, 8, 8, expected, actual);
126
        assertEquals(value, 8, 8, expected, actual);
127
128
        value = 5.22534294505995E-4;
129
        expected = "0.000522534294506";
130
        actual = format(value, 17, 17);
131
        assertEquals(value, 17, 17, expected, actual);
132
133
        value = 4.9E-324;
134
        expected = "0";
135
        actual = format(value, 309, 309);
136
        assertEquals(value, 309, 309, expected, actual);
137
138
        value = 7.003868765287485E-280;
139
        expected = refFormat(value, 294, 294);
140
        actual = format(value, 294, 294);
141
        assertEquals(value, 294, 294, expected, actual);
127
    }
142
    }
128
143
129
    public void testLimits() {
144
    public void testLimits() {
Lines 412-419 Link Here
412
427
413
        double value, highValue, lowValue;
428
        double value, highValue, lowValue;
414
        long start = System.currentTimeMillis();
429
        long start = System.currentTimeMillis();
415
        int nbTest = 100000;
430
        int nbTest = 1000000;
416
        int maxDecimals = 10;
431
        int maxDecimals = 16;
417
432
418
        r.setSeed(seed);
433
        r.setSeed(seed);
419
        start = System.currentTimeMillis();
434
        start = System.currentTimeMillis();

Return to bug 53327