mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-21 12:40:02 +00:00
ICU-13099 Merging the fix for #13118 Enabling scientific format from a normal formatter sometimes triggers OOM (r40026) to maint-59.
X-SVN-Rev: 40030
This commit is contained in:
parent
e8835a57d1
commit
ebc06007da
2 changed files with 21 additions and 7 deletions
|
@ -142,15 +142,18 @@ public class ScientificFormat extends Format.BeforeFormat implements Rounder.Mul
|
|||
private ScientificFormat(DecimalFormatSymbols symbols, IProperties properties, Rounder rounder) {
|
||||
exponentShowPlusSign = properties.getExponentSignAlwaysShown();
|
||||
exponentDigits = Math.max(1, properties.getMinimumExponentDigits());
|
||||
|
||||
// Calculate minInt/maxInt for the purposes of engineering notation:
|
||||
// 0 <= minInt <= maxInt < 8
|
||||
// The values are validated separately for rounding. This scheme needs to prevent OOM issues
|
||||
// (see #13118). Note that the bound 8 on integer digits is historic.
|
||||
int _maxInt = properties.getMaximumIntegerDigits();
|
||||
int _minInt = properties.getMinimumIntegerDigits();
|
||||
// Special behavior:
|
||||
if (_maxInt > 8) {
|
||||
_maxInt = _minInt;
|
||||
}
|
||||
maxInt = _maxInt < 0 ? Integer.MAX_VALUE : _maxInt;
|
||||
minInt = _minInt < 0 ? 0 : _minInt < maxInt ? _minInt : maxInt;
|
||||
interval = Math.max(1, maxInt);
|
||||
minInt = _minInt < 0 ? 0 : _minInt >= 8 ? 1 : _minInt;
|
||||
maxInt = _maxInt < _minInt ? _minInt : _maxInt >= 8 ? _minInt : _maxInt;
|
||||
assert 0 <= minInt && minInt <= maxInt && maxInt < 8;
|
||||
|
||||
interval = maxInt < 1 ? 1 : maxInt;
|
||||
this.rounder = rounder;
|
||||
digitStrings = symbols.getDigitStrings(); // makes a copy
|
||||
|
||||
|
|
|
@ -4992,6 +4992,17 @@ public class NumberFormatTest extends TestFmwk {
|
|||
expect2(numfmt, num, "٪ −۱٬۲۳۴");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test13118() {
|
||||
DecimalFormat df = new DecimalFormat("@@@");
|
||||
df.setScientificNotation(true);
|
||||
for (double d=12345.67; d>1e-6; d/=10) {
|
||||
String result = df.format(d);
|
||||
assertEquals("Should produce a string of expected length on " + d,
|
||||
d > 1 ? 6 : 7, result.length());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPercentZero() {
|
||||
DecimalFormat df = (DecimalFormat) NumberFormat.getPercentInstance();
|
||||
|
|
Loading…
Add table
Reference in a new issue