src/java.base/share/classes/java/text/DigitList.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58288 48e480e56aad
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
     2
 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *   The original version of this source code and documentation is copyrighted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * materials are provided under terms of a License Agreement between Taligent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * and Sun. This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * patents. This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
package java.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.math.BigDecimal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.math.RoundingMode;
34781
479b1724ab80 8145990: Move sun.misc math support classes to jdk.internal.math
chegar
parents: 27048
diff changeset
    44
import jdk.internal.math.FloatingDecimal;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Digit List. Private to DecimalFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Handles the transcoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * between numeric values and strings of characters.  Only handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * non-negative numbers.  The division of labor between DigitList and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * DecimalFormat is that DigitList handles the radix 10 representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * issues; DecimalFormat handles the locale-specific issues such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * positive/negative, grouping, decimal point, currency, and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * A DigitList is really a representation of a floating point value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * It may be an integer value; we assume that a double has sufficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * precision to represent all digits of a long.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * The DigitList representation consists of a string of characters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * which are the digits radix 10, from '0' to '9'.  It also has a radix
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * 10 exponent associated with it.  The value represented by a DigitList
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * object can be computed by mulitplying the fraction f, where 0 <= f < 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * derived by placing all the digits of the list to the right of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * decimal point, by 10^exponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
    66
 * @see  Locale
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @see  Format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @see  NumberFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @see  DecimalFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @see  ChoiceFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @see  MessageFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @author       Mark Davis, Alan Liu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
final class DigitList implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * The maximum number of significant digits in an IEEE 754 double, that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * is, in a Java double.  This must not be increased, or garbage digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * will be generated, and should not be decreased, or accuracy will be lost.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static final int MAX_COUNT = 19; // == Long.toString(Long.MAX_VALUE).length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * These data members are intentionally public and can be set directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * The value represented is given by placing the decimal point before
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * digits[decimalAt].  If decimalAt is < 0, then leading zeros between
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * the decimal point and the first nonzero digit are implied.  If decimalAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * is > count, then trailing zeros between the digits[count-1] and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * decimal point are implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Equivalently, the represented value is given by f * 10^decimalAt.  Here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * f is a value 0.1 <= f < 1 arrived at by placing the digits in Digits to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * the right of the decimal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * DigitList is normalized, so if it is non-zero, figits[0] is non-zero.  We
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * don't allow denormalized numbers because our exponent is effectively of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * unlimited magnitude.  The count value contains the number of significant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * digits present in digits[].
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Zero is represented by any DigitList with count == 0 or with each digits[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * for all i <= count == '0'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public int decimalAt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public char[] digits = new char[MAX_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private char[] data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private RoundingMode roundingMode = RoundingMode.HALF_EVEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private boolean isNegative = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Return true if the represented number is zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    boolean isZero() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        for (int i=0; i < count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            if (digits[i] != '0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Set the rounding mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    void setRoundingMode(RoundingMode r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        roundingMode = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Clears out the digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Use before appending them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Typically, you set a series of digits with append, then at the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * you hit the decimal point, you set myDigitList.decimalAt = myDigitList.count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * then go on appending digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public void clear () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        decimalAt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Appends a digit to the list, extending the list when necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public void append(char digit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (count == digits.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            char[] data = new char[count + 100];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            System.arraycopy(digits, 0, data, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            digits = data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        digits[count++] = digit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Utility routine to get the value of the digit list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * If (count == 0) this throws a NumberFormatException, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * mimics Long.parseLong().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public final double getDouble() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (count == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        StringBuffer temp = getStringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        temp.append('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        temp.append(digits, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        temp.append('E');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        temp.append(decimalAt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return Double.parseDouble(temp.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Utility routine to get the value of the digit list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * If (count == 0) this returns 0, unlike Long.parseLong().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public final long getLong() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        // for now, simple implementation; later, do proper IEEE native stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (count == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        // We have to check for this, because this is the one NEGATIVE value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        // we represent.  If we tried to just pass the digits off to parseLong,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        // we'd get a parse failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (isLongMIN_VALUE()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            return Long.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        StringBuffer temp = getStringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        temp.append(digits, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        for (int i = count; i < decimalAt; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            temp.append('0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return Long.parseLong(temp.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public final BigDecimal getBigDecimal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (count == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            if (decimalAt == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                return BigDecimal.ZERO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                return new BigDecimal("0E" + decimalAt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
       if (decimalAt == count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
           return new BigDecimal(digits, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
       } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
           return new BigDecimal(digits, 0, count).scaleByPowerOfTen(decimalAt - count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Return true if the number represented by this object can fit into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * a long.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param isPositive true if this number should be regarded as positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param ignoreNegativeZero true if -0 should be regarded as identical to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * +0; otherwise they are considered distinct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return true if this number fits into a Java long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    boolean fitsIntoLong(boolean isPositive, boolean ignoreNegativeZero) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        // Figure out if the result will fit in a long.  We have to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // first look for nonzero digits after the decimal point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        // then check the size.  If the digit count is 18 or less, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        // the value can definitely be represented as a long.  If it is 19
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        // then it may be too large.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // Trim trailing zeros.  This does not change the represented value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        while (count > 0 && digits[count - 1] == '0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            --count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (count == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            // Positive zero fits into a long, but negative zero can only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            // be represented as a double. - bug 4162852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            return isPositive || ignoreNegativeZero;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (decimalAt < count || decimalAt > MAX_COUNT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (decimalAt < MAX_COUNT) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        // At this point we have decimalAt == count, and count == MAX_COUNT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // The number will overflow if it is larger than 9223372036854775807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        // or smaller than -9223372036854775808.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        for (int i=0; i<count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            char dig = digits[i], max = LONG_MIN_REP[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            if (dig > max) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (dig < max) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        // At this point the first count digits match.  If decimalAt is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        // than count, then the remaining digits are zero, and we return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (count < decimalAt) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // Now we have a representation of Long.MIN_VALUE, without the leading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        // negative sign.  If this represents a positive value, then it does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        // not fit; otherwise it fits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return !isPositive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Set the digit list to a representation of the given double value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * This method supports fixed-point notation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param isNegative Boolean value indicating whether the number is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param source Value to be converted; must not be Inf, -Inf, Nan,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * or a value <= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @param maximumFractionDigits The most fractional digits which should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * be converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15255
diff changeset
   274
    final void set(boolean isNegative, double source, int maximumFractionDigits) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        set(isNegative, source, maximumFractionDigits, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * Set the digit list to a representation of the given double value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * This method supports both fixed-point and exponential notation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @param isNegative Boolean value indicating whether the number is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param source Value to be converted; must not be Inf, -Inf, Nan,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * or a value <= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @param maximumDigits The most fractional or total digits which should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * be converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @param fixedPoint If true, then maximumDigits is the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * fractional digits to be converted.  If false, total digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    final void set(boolean isNegative, double source, int maximumDigits, boolean fixedPoint) {
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   290
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15255
diff changeset
   291
        FloatingDecimal.BinaryToASCIIConverter fdConverter  = FloatingDecimal.getBinaryToASCIIConverter(source);
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15255
diff changeset
   292
        boolean hasBeenRoundedUp = fdConverter.digitsRoundedUp();
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   293
        boolean valueExactAsDecimal = fdConverter.decimalDigitsExact();
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15255
diff changeset
   294
        assert !fdConverter.isExceptional();
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15255
diff changeset
   295
        String digitsString = fdConverter.toJavaFormatString();
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   296
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   297
        set(isNegative, digitsString,
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   298
            hasBeenRoundedUp, valueExactAsDecimal,
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   299
            maximumDigits, fixedPoint);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Generate a representation of the form DDDDD, DDDDD.DDDDD, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * DDDDDE+/-DDDDD.
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   305
     * @param roundedUp whether or not rounding up has already happened.
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   306
     * @param valueExactAsDecimal whether or not collected digits provide
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   307
     * an exact decimal representation of the value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15255
diff changeset
   309
    private void set(boolean isNegative, String s,
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   310
                     boolean roundedUp, boolean valueExactAsDecimal,
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15255
diff changeset
   311
                     int maximumDigits, boolean fixedPoint) {
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   312
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        this.isNegative = isNegative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        int len = s.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        char[] source = getDataChars(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        s.getChars(0, len, source, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        decimalAt = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        int exponent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        // Number of zeros between decimal point and first non-zero digit after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        // decimal point, for numbers < 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        int leadingZerosAfterDecimal = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        boolean nonZeroDigitSeen = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        for (int i = 0; i < len; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            char c = source[i++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if (c == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                decimalAt = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            } else if (c == 'e' || c == 'E') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                exponent = parseInt(source, i, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                if (!nonZeroDigitSeen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    nonZeroDigitSeen = (c != '0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    if (!nonZeroDigitSeen && decimalAt != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                        ++leadingZerosAfterDecimal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                if (nonZeroDigitSeen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    digits[count++] = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (decimalAt == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            decimalAt = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (nonZeroDigitSeen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            decimalAt += exponent - leadingZerosAfterDecimal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (fixedPoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            // The negative of the exponent represents the number of leading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            // zeros between the decimal and the first non-zero digit, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            // a value < 0.1 (e.g., for 0.00123, -decimalAt == 2).  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            // is more than the maximum fraction digits, then we have an underflow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            // for the printed representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (-decimalAt > maximumDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                // Handle an underflow to zero when we round something like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                // 0.0009 to 2 fractional digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            } else if (-decimalAt == maximumDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                // If we round 0.0009 to 3 fractional digits, then we have to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                // create a new one digit in the least significant location.
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   365
                if (shouldRoundUp(0, roundedUp, valueExactAsDecimal)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    count = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    ++decimalAt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    digits[0] = '1';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            // else fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        // Eliminate trailing zeros.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        while (count > 1 && digits[count - 1] == '0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            --count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        // Eliminate digits beyond maximum digits to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        // Round up if appropriate.
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   384
        round(fixedPoint ? (maximumDigits + decimalAt) : maximumDigits,
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   385
              roundedUp, valueExactAsDecimal);
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   386
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   387
     }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Round the representation to the given number of digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param maximumDigits The maximum number of digits to be shown.
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   392
     * @param alreadyRounded whether or not rounding up has already happened.
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   393
     * @param valueExactAsDecimal whether or not collected digits provide
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   394
     * an exact decimal representation of the value.
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   395
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * Upon return, count will be less than or equal to maximumDigits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   398
    private final void round(int maximumDigits,
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   399
                             boolean alreadyRounded,
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   400
                             boolean valueExactAsDecimal) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        // Eliminate digits beyond maximum digits to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        // Round up if appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (maximumDigits >= 0 && maximumDigits < count) {
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   404
            if (shouldRoundUp(maximumDigits, alreadyRounded, valueExactAsDecimal)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                // Rounding up involved incrementing digits from LSD to MSD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                // In most cases this is simple, but in a worst case situation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                // (9999..99) we have to adjust the decimalAt value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    --maximumDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    if (maximumDigits < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                        // We have all 9's, so we increment to a single digit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                        // of one and adjust the exponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                        digits[0] = '1';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                        ++decimalAt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                        maximumDigits = 0; // Adjust the count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    ++digits[maximumDigits];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    if (digits[maximumDigits] <= '9') break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    // digits[maximumDigits] = '0'; // Unnecessary since we'll truncate this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                ++maximumDigits; // Increment for use as count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            count = maximumDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            // Eliminate trailing zeros.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            while (count > 1 && digits[count-1] == '0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                --count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Return true if truncating the representation to the given number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * of digits will result in an increment to the last digit.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * method implements the rounding modes defined in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * java.math.RoundingMode class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * [bnf]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @param maximumDigits the number of digits to keep, from 0 to
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   442
     * {@code count-1}.  If 0, then all digits are rounded away, and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * this method returns true if a one should be generated (e.g., formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * 0.09 with "#.#").
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   445
     * @param alreadyRounded whether or not rounding up has already happened.
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   446
     * @param valueExactAsDecimal whether or not collected digits provide
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   447
     * an exact decimal representation of the value.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   448
     * @throws    ArithmeticException if rounding is needed with rounding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *            mode being set to RoundingMode.UNNECESSARY
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   450
     * @return true if digit {@code maximumDigits-1} should be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * incremented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   453
    private boolean shouldRoundUp(int maximumDigits,
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   454
                                  boolean alreadyRounded,
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   455
                                  boolean valueExactAsDecimal) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (maximumDigits < count) {
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   457
            /*
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   458
             * To avoid erroneous double-rounding or truncation when converting
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   459
             * a binary double value to text, information about the exactness
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   460
             * of the conversion result in FloatingDecimal, as well as any
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   461
             * rounding done, is needed in this class.
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   462
             *
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   463
             * - For the  HALF_DOWN, HALF_EVEN, HALF_UP rounding rules below:
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   464
             *   In the case of formating float or double, We must take into
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   465
             *   account what FloatingDecimal has done in the binary to decimal
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   466
             *   conversion.
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   467
             *
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   468
             *   Considering the tie cases, FloatingDecimal may round up the
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   469
             *   value (returning decimal digits equal to tie when it is below),
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   470
             *   or "truncate" the value to the tie while value is above it,
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   471
             *   or provide the exact decimal digits when the binary value can be
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   472
             *   converted exactly to its decimal representation given formating
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   473
             *   rules of FloatingDecimal ( we have thus an exact decimal
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   474
             *   representation of the binary value).
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   475
             *
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   476
             *   - If the double binary value was converted exactly as a decimal
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   477
             *     value, then DigitList code must apply the expected rounding
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   478
             *     rule.
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   479
             *
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   480
             *   - If FloatingDecimal already rounded up the decimal value,
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   481
             *     DigitList should neither round up the value again in any of
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   482
             *     the three rounding modes above.
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   483
             *
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   484
             *   - If FloatingDecimal has truncated the decimal value to
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   485
             *     an ending '5' digit, DigitList should round up the value in
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   486
             *     all of the three rounding modes above.
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   487
             *
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   488
             *
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   489
             *   This has to be considered only if digit at maximumDigits index
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   490
             *   is exactly the last one in the set of digits, otherwise there are
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18143
diff changeset
   491
             *   remaining digits after that position and we don't have to consider
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   492
             *   what FloatingDecimal did.
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   493
             *
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   494
             * - Other rounding modes are not impacted by these tie cases.
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   495
             *
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   496
             * - For other numbers that are always converted to exact digits
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   497
             *   (like BigInteger, Long, ...), the passed alreadyRounded boolean
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   498
             *   have to be  set to false, and valueExactAsDecimal has to be set to
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   499
             *   true in the upper DigitList call stack, providing the right state
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   500
             *   for those situations..
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   501
             */
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   502
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            switch(roundingMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            case UP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                for (int i=maximumDigits; i<count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                    if (digits[i] != '0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            case DOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            case CEILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                for (int i=maximumDigits; i<count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    if (digits[i] != '0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        return !isNegative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            case FLOOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                for (int i=maximumDigits; i<count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    if (digits[i] != '0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                        return isNegative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            case HALF_UP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            case HALF_DOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                if (digits[maximumDigits] > '5') {
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   530
                    // Value is above tie ==> must round up
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    return true;
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   532
                } else if (digits[maximumDigits] == '5') {
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   533
                    // Digit at rounding position is a '5'. Tie cases.
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   534
                    if (maximumDigits != (count - 1)) {
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   535
                        // There are remaining digits. Above tie => must round up
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   536
                        return true;
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   537
                    } else {
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   538
                        // Digit at rounding position is the last one !
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   539
                        if (valueExactAsDecimal) {
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   540
                            // Exact binary representation. On the tie.
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   541
                            // Apply rounding given by roundingMode.
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   542
                            return roundingMode == RoundingMode.HALF_UP;
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   543
                        } else {
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   544
                            // Not an exact binary representation.
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   545
                            // Digit sequence either rounded up or truncated.
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   546
                            // Round up only if it was truncated.
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   547
                            return !alreadyRounded;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                }
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   551
                // Digit at rounding position is < '5' ==> no round up.
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   552
                // Just let do the default, which is no round up (thus break).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            case HALF_EVEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                // Implement IEEE half-even rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                if (digits[maximumDigits] > '5') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                } else if (digits[maximumDigits] == '5' ) {
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   559
                    if (maximumDigits == (count - 1)) {
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   560
                        // the rounding position is exactly the last index :
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   561
                        if (alreadyRounded)
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   562
                            // If FloatingDecimal rounded up (value was below tie),
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   563
                            // then we should not round up again.
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   564
                            return false;
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   565
27048
e60960edecfb 8039915: Wrong NumberFormat.format() HALF_UP rounding when last digit exactly at rounding position greater than 5
bpb
parents: 25859
diff changeset
   566
                        if (!valueExactAsDecimal)
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18143
diff changeset
   567
                            // Otherwise if the digits don't represent exact value,
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   568
                            // value was above tie and FloatingDecimal truncated
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   569
                            // digits to tie. We must round up.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                            return true;
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   571
                        else {
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   572
                            // This is an exact tie value, and FloatingDecimal
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   573
                            // provided all of the exact digits. We thus apply
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   574
                            // HALF_EVEN rounding rule.
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   575
                            return ((maximumDigits > 0) &&
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   576
                                    (digits[maximumDigits-1] % 2 != 0));
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   577
                        }
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   578
                    } else {
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   579
                        // Rounds up if it gives a non null digit after '5'
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   580
                        for (int i=maximumDigits+1; i<count; ++i) {
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   581
                            if (digits[i] != '0')
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   582
                                return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            case UNNECESSARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                for (int i=maximumDigits; i<count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    if (digits[i] != '0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                        throw new ArithmeticException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                            "Rounding needed with the rounding mode being set to RoundingMode.UNNECESSARY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * Utility routine to set the value of the digit list from a long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15255
diff changeset
   605
    final void set(boolean isNegative, long source) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        set(isNegative, source, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * Set the digit list to a representation of the given long value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @param isNegative Boolean value indicating whether the number is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @param source Value to be converted; must be >= 0 or ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * Long.MIN_VALUE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @param maximumDigits The most digits which should be converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * If maximumDigits is lower than the number of significant digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * in source, the representation will be rounded.  Ignored if <= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15255
diff changeset
   618
    final void set(boolean isNegative, long source, int maximumDigits) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        this.isNegative = isNegative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        // This method does not expect a negative number. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        // "source" can be a Long.MIN_VALUE (-9223372036854775808),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        // if the number being formatted is a Long.MIN_VALUE.  In that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        // case, it will be formatted as -Long.MIN_VALUE, a number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        // which is outside the legal range of a long, but which can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        // be represented by DigitList.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        if (source <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            if (source == Long.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                decimalAt = count = MAX_COUNT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                System.arraycopy(LONG_MIN_REP, 0, digits, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                decimalAt = count = 0; // Values <= 0 format as zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            // Rewritten to improve performance.  I used to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            // Long.toString(), which was about 4x slower than this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            int left = MAX_COUNT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            int right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            while (source > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                digits[--left] = (char)('0' + (source % 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                source /= 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            decimalAt = MAX_COUNT - left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            // Don't copy trailing zeros.  We are guaranteed that there is at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            // least one non-zero digit, so we don't have to check lower bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            for (right = MAX_COUNT - 1; digits[right] == '0'; --right)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            count = right - left + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            System.arraycopy(digits, left, digits, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        }
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   651
        if (maximumDigits > 0) round(maximumDigits, false, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * Set the digit list to a representation of the given BigDecimal value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * This method supports both fixed-point and exponential notation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @param isNegative Boolean value indicating whether the number is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @param source Value to be converted; must not be a value <= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @param maximumDigits The most fractional or total digits which should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * be converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @param fixedPoint If true, then maximumDigits is the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * fractional digits to be converted.  If false, total digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    final void set(boolean isNegative, BigDecimal source, int maximumDigits, boolean fixedPoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        String s = source.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        extendDigits(s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   668
        set(isNegative, s,
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   669
            false, true,
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   670
            maximumDigits, fixedPoint);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * Set the digit list to a representation of the given BigInteger value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @param isNegative Boolean value indicating whether the number is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @param source Value to be converted; must be >= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * @param maximumDigits The most digits which should be converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * If maximumDigits is lower than the number of significant digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * in source, the representation will be rounded.  Ignored if <= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    final void set(boolean isNegative, BigInteger source, int maximumDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        this.isNegative = isNegative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        String s = source.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        int len = s.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        extendDigits(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        s.getChars(0, len, digits, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        decimalAt = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        int right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        for (right = len - 1; right >= 0 && digits[right] == '0'; --right)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        count = right + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        if (maximumDigits > 0) {
15255
0b53a05e0b07 7131459: [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
darcy
parents: 14342
diff changeset
   695
            round(maximumDigits, false, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * equality test between two digit lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        if (this == obj)                      // quick check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        if (!(obj instanceof DigitList))         // (1) same object?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        DigitList other = (DigitList) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        if (count != other.count ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        decimalAt != other.decimalAt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        for (int i = 0; i < count; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            if (digits[i] != other.digits[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * Generates the hash code for the digit list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        int hashcode = decimalAt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            hashcode = hashcode * 37 + digits[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        return hashcode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * Creates a copy of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @return a clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            DigitList other = (DigitList) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            char[] newDigits = new char[digits.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            System.arraycopy(digits, 0, newDigits, 0, digits.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            other.digits = newDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            other.tempBuffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            return other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        } catch (CloneNotSupportedException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   743
            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * Returns true if this DigitList represents Long.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * false, otherwise.  This is required so that getLong() works.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    private boolean isLongMIN_VALUE() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        if (decimalAt != count || count != MAX_COUNT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        for (int i = 0; i < count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            if (digits[i] != LONG_MIN_REP[i]) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    private static final int parseInt(char[] str, int offset, int strLen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        char c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        boolean positive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        if ((c = str[offset]) == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            positive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            offset++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        } else if (c == '+') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            offset++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        while (offset < strLen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            c = str[offset++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            if (c >= '0' && c <= '9') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                value = value * 10 + (c - '0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        return positive ? value : -value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    // The digit part of -9223372036854775808L
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    private static final char[] LONG_MIN_REP = "9223372036854775808".toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        if (isZero()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            return "0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        StringBuffer buf = getStringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        buf.append("0.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        buf.append(digits, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        buf.append("x10^");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        buf.append(decimalAt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    private StringBuffer tempBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    private StringBuffer getStringBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        if (tempBuffer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            tempBuffer = new StringBuffer(MAX_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            tempBuffer.setLength(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        return tempBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    private void extendDigits(int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        if (len > digits.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            digits = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    private final char[] getDataChars(int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        if (data == null || data.length < length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            data = new char[length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
}