0N/A/*
2362N/A * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
0N/A * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
0N/A *
0N/A * The original version of this source code and documentation is copyrighted
0N/A * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
0N/A * materials are provided under terms of a License Agreement between Taligent
0N/A * and Sun. This technology is protected by multiple US and International
0N/A * patents. This notice and attribution to Taligent may not be removed.
0N/A * Taligent is a registered trademark of Taligent, Inc.
0N/A *
0N/A */
0N/A
0N/Apackage java.text;
0N/A
0N/Aimport java.math.BigDecimal;
0N/Aimport java.math.BigInteger;
0N/Aimport java.math.RoundingMode;
0N/A
0N/A/**
0N/A * Digit List. Private to DecimalFormat.
0N/A * Handles the transcoding
0N/A * between numeric values and strings of characters. Only handles
0N/A * non-negative numbers. The division of labor between DigitList and
0N/A * DecimalFormat is that DigitList handles the radix 10 representation
0N/A * issues; DecimalFormat handles the locale-specific issues such as
0N/A * positive/negative, grouping, decimal point, currency, and so on.
0N/A *
0N/A * A DigitList is really a representation of a floating point value.
0N/A * It may be an integer value; we assume that a double has sufficient
0N/A * precision to represent all digits of a long.
0N/A *
0N/A * The DigitList representation consists of a string of characters,
0N/A * which are the digits radix 10, from '0' to '9'. It also has a radix
0N/A * 10 exponent associated with it. The value represented by a DigitList
0N/A * object can be computed by mulitplying the fraction f, where 0 <= f < 1,
0N/A * derived by placing all the digits of the list to the right of the
0N/A * decimal point, by 10^exponent.
0N/A *
0N/A * @see Locale
0N/A * @see Format
0N/A * @see NumberFormat
0N/A * @see DecimalFormat
0N/A * @see ChoiceFormat
0N/A * @see MessageFormat
0N/A * @author Mark Davis, Alan Liu
0N/A */
0N/Afinal class DigitList implements Cloneable {
0N/A /**
0N/A * The maximum number of significant digits in an IEEE 754 double, that
0N/A * is, in a Java double. This must not be increased, or garbage digits
0N/A * will be generated, and should not be decreased, or accuracy will be lost.
0N/A */
0N/A public static final int MAX_COUNT = 19; // == Long.toString(Long.MAX_VALUE).length()
0N/A
0N/A /**
0N/A * These data members are intentionally public and can be set directly.
0N/A *
0N/A * The value represented is given by placing the decimal point before
0N/A * digits[decimalAt]. If decimalAt is < 0, then leading zeros between
0N/A * the decimal point and the first nonzero digit are implied. If decimalAt
0N/A * is > count, then trailing zeros between the digits[count-1] and the
0N/A * decimal point are implied.
0N/A *
0N/A * Equivalently, the represented value is given by f * 10^decimalAt. Here
0N/A * f is a value 0.1 <= f < 1 arrived at by placing the digits in Digits to
0N/A * the right of the decimal.
0N/A *
0N/A * DigitList is normalized, so if it is non-zero, figits[0] is non-zero. We
0N/A * don't allow denormalized numbers because our exponent is effectively of
0N/A * unlimited magnitude. The count value contains the number of significant
0N/A * digits present in digits[].
0N/A *
0N/A * Zero is represented by any DigitList with count == 0 or with each digits[i]
0N/A * for all i <= count == '0'.
0N/A */
0N/A public int decimalAt = 0;
0N/A public int count = 0;
0N/A public char[] digits = new char[MAX_COUNT];
0N/A
0N/A private char[] data;
0N/A private RoundingMode roundingMode = RoundingMode.HALF_EVEN;
0N/A private boolean isNegative = false;
0N/A
0N/A /**
0N/A * Return true if the represented number is zero.
0N/A */
0N/A boolean isZero() {
0N/A for (int i=0; i < count; ++i) {
0N/A if (digits[i] != '0') {
0N/A return false;
0N/A }
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Set the rounding mode
0N/A */
0N/A void setRoundingMode(RoundingMode r) {
0N/A roundingMode = r;
0N/A }
0N/A
0N/A /**
0N/A * Clears out the digits.
0N/A * Use before appending them.
0N/A * Typically, you set a series of digits with append, then at the point
0N/A * you hit the decimal point, you set myDigitList.decimalAt = myDigitList.count;
0N/A * then go on appending digits.
0N/A */
0N/A public void clear () {
0N/A decimalAt = 0;
0N/A count = 0;
0N/A }
0N/A
0N/A /**
0N/A * Appends a digit to the list, extending the list when necessary.
0N/A */
0N/A public void append(char digit) {
0N/A if (count == digits.length) {
0N/A char[] data = new char[count + 100];
0N/A System.arraycopy(digits, 0, data, 0, count);
0N/A digits = data;
0N/A }
0N/A digits[count++] = digit;
0N/A }
0N/A
0N/A /**
0N/A * Utility routine to get the value of the digit list
0N/A * If (count == 0) this throws a NumberFormatException, which
0N/A * mimics Long.parseLong().
0N/A */
0N/A public final double getDouble() {
0N/A if (count == 0) {
0N/A return 0.0;
0N/A }
0N/A
0N/A StringBuffer temp = getStringBuffer();
0N/A temp.append('.');
0N/A temp.append(digits, 0, count);
0N/A temp.append('E');
0N/A temp.append(decimalAt);
0N/A return Double.parseDouble(temp.toString());
0N/A }
0N/A
0N/A /**
0N/A * Utility routine to get the value of the digit list.
0N/A * If (count == 0) this returns 0, unlike Long.parseLong().
0N/A */
0N/A public final long getLong() {
0N/A // for now, simple implementation; later, do proper IEEE native stuff
0N/A
0N/A if (count == 0) {
0N/A return 0;
0N/A }
0N/A
0N/A // We have to check for this, because this is the one NEGATIVE value
0N/A // we represent. If we tried to just pass the digits off to parseLong,
0N/A // we'd get a parse failure.
0N/A if (isLongMIN_VALUE()) {
0N/A return Long.MIN_VALUE;
0N/A }
0N/A
0N/A StringBuffer temp = getStringBuffer();
0N/A temp.append(digits, 0, count);
0N/A for (int i = count; i < decimalAt; ++i) {
0N/A temp.append('0');
0N/A }
0N/A return Long.parseLong(temp.toString());
0N/A }
0N/A
0N/A public final BigDecimal getBigDecimal() {
0N/A if (count == 0) {
0N/A if (decimalAt == 0) {
0N/A return BigDecimal.ZERO;
0N/A } else {
0N/A return new BigDecimal("0E" + decimalAt);
0N/A }
0N/A }
0N/A
0N/A if (decimalAt == count) {
0N/A return new BigDecimal(digits, 0, count);
0N/A } else {
0N/A return new BigDecimal(digits, 0, count).scaleByPowerOfTen(decimalAt - count);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Return true if the number represented by this object can fit into
0N/A * a long.
0N/A * @param isPositive true if this number should be regarded as positive
0N/A * @param ignoreNegativeZero true if -0 should be regarded as identical to
0N/A * +0; otherwise they are considered distinct
0N/A * @return true if this number fits into a Java long
0N/A */
0N/A boolean fitsIntoLong(boolean isPositive, boolean ignoreNegativeZero) {
0N/A // Figure out if the result will fit in a long. We have to
0N/A // first look for nonzero digits after the decimal point;
0N/A // then check the size. If the digit count is 18 or less, then
0N/A // the value can definitely be represented as a long. If it is 19
0N/A // then it may be too large.
0N/A
0N/A // Trim trailing zeros. This does not change the represented value.
0N/A while (count > 0 && digits[count - 1] == '0') {
0N/A --count;
0N/A }
0N/A
0N/A if (count == 0) {
0N/A // Positive zero fits into a long, but negative zero can only
0N/A // be represented as a double. - bug 4162852
0N/A return isPositive || ignoreNegativeZero;
0N/A }
0N/A
0N/A if (decimalAt < count || decimalAt > MAX_COUNT) {
0N/A return false;
0N/A }
0N/A
0N/A if (decimalAt < MAX_COUNT) return true;
0N/A
0N/A // At this point we have decimalAt == count, and count == MAX_COUNT.
0N/A // The number will overflow if it is larger than 9223372036854775807
0N/A // or smaller than -9223372036854775808.
0N/A for (int i=0; i<count; ++i) {
0N/A char dig = digits[i], max = LONG_MIN_REP[i];
0N/A if (dig > max) return false;
0N/A if (dig < max) return true;
0N/A }
0N/A
0N/A // At this point the first count digits match. If decimalAt is less
0N/A // than count, then the remaining digits are zero, and we return true.
0N/A if (count < decimalAt) return true;
0N/A
0N/A // Now we have a representation of Long.MIN_VALUE, without the leading
0N/A // negative sign. If this represents a positive value, then it does
0N/A // not fit; otherwise it fits.
0N/A return !isPositive;
0N/A }
0N/A
0N/A /**
0N/A * Set the digit list to a representation of the given double value.
0N/A * This method supports fixed-point notation.
0N/A * @param isNegative Boolean value indicating whether the number is negative.
0N/A * @param source Value to be converted; must not be Inf, -Inf, Nan,
0N/A * or a value <= 0.
0N/A * @param maximumFractionDigits The most fractional digits which should
0N/A * be converted.
0N/A */
0N/A public final void set(boolean isNegative, double source, int maximumFractionDigits) {
0N/A set(isNegative, source, maximumFractionDigits, true);
0N/A }
0N/A
0N/A /**
0N/A * Set the digit list to a representation of the given double value.
0N/A * This method supports both fixed-point and exponential notation.
0N/A * @param isNegative Boolean value indicating whether the number is negative.
0N/A * @param source Value to be converted; must not be Inf, -Inf, Nan,
0N/A * or a value <= 0.
0N/A * @param maximumDigits The most fractional or total digits which should
0N/A * be converted.
0N/A * @param fixedPoint If true, then maximumDigits is the maximum
0N/A * fractional digits to be converted. If false, total digits.
0N/A */
0N/A final void set(boolean isNegative, double source, int maximumDigits, boolean fixedPoint) {
0N/A set(isNegative, Double.toString(source), maximumDigits, fixedPoint);
0N/A }
0N/A
0N/A /**
0N/A * Generate a representation of the form DDDDD, DDDDD.DDDDD, or
0N/A * DDDDDE+/-DDDDD.
0N/A */
0N/A final void set(boolean isNegative, String s, int maximumDigits, boolean fixedPoint) {
0N/A this.isNegative = isNegative;
0N/A int len = s.length();
0N/A char[] source = getDataChars(len);
0N/A s.getChars(0, len, source, 0);
0N/A
0N/A decimalAt = -1;
0N/A count = 0;
0N/A int exponent = 0;
0N/A // Number of zeros between decimal point and first non-zero digit after
0N/A // decimal point, for numbers < 1.
0N/A int leadingZerosAfterDecimal = 0;
0N/A boolean nonZeroDigitSeen = false;
0N/A
0N/A for (int i = 0; i < len; ) {
0N/A char c = source[i++];
0N/A if (c == '.') {
0N/A decimalAt = count;
0N/A } else if (c == 'e' || c == 'E') {
0N/A exponent = parseInt(source, i, len);
0N/A break;
0N/A } else {
0N/A if (!nonZeroDigitSeen) {
0N/A nonZeroDigitSeen = (c != '0');
0N/A if (!nonZeroDigitSeen && decimalAt != -1)
0N/A ++leadingZerosAfterDecimal;
0N/A }
0N/A if (nonZeroDigitSeen) {
0N/A digits[count++] = c;
0N/A }
0N/A }
0N/A }
0N/A if (decimalAt == -1) {
0N/A decimalAt = count;
0N/A }
0N/A if (nonZeroDigitSeen) {
0N/A decimalAt += exponent - leadingZerosAfterDecimal;
0N/A }
0N/A
0N/A if (fixedPoint) {
0N/A // The negative of the exponent represents the number of leading
0N/A // zeros between the decimal and the first non-zero digit, for
0N/A // a value < 0.1 (e.g., for 0.00123, -decimalAt == 2). If this
0N/A // is more than the maximum fraction digits, then we have an underflow
0N/A // for the printed representation.
0N/A if (-decimalAt > maximumDigits) {
0N/A // Handle an underflow to zero when we round something like
0N/A // 0.0009 to 2 fractional digits.
0N/A count = 0;
0N/A return;
0N/A } else if (-decimalAt == maximumDigits) {
0N/A // If we round 0.0009 to 3 fractional digits, then we have to
0N/A // create a new one digit in the least significant location.
0N/A if (shouldRoundUp(0)) {
0N/A count = 1;
0N/A ++decimalAt;
0N/A digits[0] = '1';
0N/A } else {
0N/A count = 0;
0N/A }
0N/A return;
0N/A }
0N/A // else fall through
0N/A }
0N/A
0N/A // Eliminate trailing zeros.
0N/A while (count > 1 && digits[count - 1] == '0') {
0N/A --count;
0N/A }
0N/A
0N/A // Eliminate digits beyond maximum digits to be displayed.
0N/A // Round up if appropriate.
0N/A round(fixedPoint ? (maximumDigits + decimalAt) : maximumDigits);
0N/A }
0N/A
0N/A /**
0N/A * Round the representation to the given number of digits.
0N/A * @param maximumDigits The maximum number of digits to be shown.
0N/A * Upon return, count will be less than or equal to maximumDigits.
0N/A */
0N/A private final void round(int maximumDigits) {
0N/A // Eliminate digits beyond maximum digits to be displayed.
0N/A // Round up if appropriate.
0N/A if (maximumDigits >= 0 && maximumDigits < count) {
0N/A if (shouldRoundUp(maximumDigits)) {
0N/A // Rounding up involved incrementing digits from LSD to MSD.
0N/A // In most cases this is simple, but in a worst case situation
0N/A // (9999..99) we have to adjust the decimalAt value.
0N/A for (;;) {
0N/A --maximumDigits;
0N/A if (maximumDigits < 0) {
0N/A // We have all 9's, so we increment to a single digit
0N/A // of one and adjust the exponent.
0N/A digits[0] = '1';
0N/A ++decimalAt;
0N/A maximumDigits = 0; // Adjust the count
0N/A break;
0N/A }
0N/A
0N/A ++digits[maximumDigits];
0N/A if (digits[maximumDigits] <= '9') break;
0N/A // digits[maximumDigits] = '0'; // Unnecessary since we'll truncate this
0N/A }
0N/A ++maximumDigits; // Increment for use as count
0N/A }
0N/A count = maximumDigits;
0N/A
0N/A // Eliminate trailing zeros.
0N/A while (count > 1 && digits[count-1] == '0') {
0N/A --count;
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Return true if truncating the representation to the given number
0N/A * of digits will result in an increment to the last digit. This
0N/A * method implements the rounding modes defined in the
0N/A * java.math.RoundingMode class.
0N/A * [bnf]
0N/A * @param maximumDigits the number of digits to keep, from 0 to
0N/A * <code>count-1</code>. If 0, then all digits are rounded away, and
0N/A * this method returns true if a one should be generated (e.g., formatting
0N/A * 0.09 with "#.#").
0N/A * @exception ArithmeticException if rounding is needed with rounding
0N/A * mode being set to RoundingMode.UNNECESSARY
0N/A * @return true if digit <code>maximumDigits-1</code> should be
0N/A * incremented
0N/A */
0N/A private boolean shouldRoundUp(int maximumDigits) {
0N/A if (maximumDigits < count) {
0N/A switch(roundingMode) {
0N/A case UP:
0N/A for (int i=maximumDigits; i<count; ++i) {
0N/A if (digits[i] != '0') {
0N/A return true;
0N/A }
0N/A }
0N/A break;
0N/A case DOWN:
0N/A break;
0N/A case CEILING:
0N/A for (int i=maximumDigits; i<count; ++i) {
0N/A if (digits[i] != '0') {
0N/A return !isNegative;
0N/A }
0N/A }
0N/A break;
0N/A case FLOOR:
0N/A for (int i=maximumDigits; i<count; ++i) {
0N/A if (digits[i] != '0') {
0N/A return isNegative;
0N/A }
0N/A }
0N/A break;
0N/A case HALF_UP:
0N/A if (digits[maximumDigits] >= '5') {
0N/A return true;
0N/A }
0N/A break;
0N/A case HALF_DOWN:
0N/A if (digits[maximumDigits] > '5') {
0N/A return true;
0N/A } else if (digits[maximumDigits] == '5' ) {
0N/A for (int i=maximumDigits+1; i<count; ++i) {
0N/A if (digits[i] != '0') {
0N/A return true;
0N/A }
0N/A }
0N/A }
0N/A break;
0N/A case HALF_EVEN:
0N/A // Implement IEEE half-even rounding
0N/A if (digits[maximumDigits] > '5') {
0N/A return true;
0N/A } else if (digits[maximumDigits] == '5' ) {
0N/A for (int i=maximumDigits+1; i<count; ++i) {
0N/A if (digits[i] != '0') {
0N/A return true;
0N/A }
0N/A }
0N/A return maximumDigits > 0 && (digits[maximumDigits-1] % 2 != 0);
0N/A }
0N/A break;
0N/A case UNNECESSARY:
0N/A for (int i=maximumDigits; i<count; ++i) {
0N/A if (digits[i] != '0') {
0N/A throw new ArithmeticException(
0N/A "Rounding needed with the rounding mode being set to RoundingMode.UNNECESSARY");
0N/A }
0N/A }
0N/A break;
0N/A default:
0N/A assert false;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Utility routine to set the value of the digit list from a long
0N/A */
0N/A public final void set(boolean isNegative, long source) {
0N/A set(isNegative, source, 0);
0N/A }
0N/A
0N/A /**
0N/A * Set the digit list to a representation of the given long value.
0N/A * @param isNegative Boolean value indicating whether the number is negative.
0N/A * @param source Value to be converted; must be >= 0 or ==
0N/A * Long.MIN_VALUE.
0N/A * @param maximumDigits The most digits which should be converted.
0N/A * If maximumDigits is lower than the number of significant digits
0N/A * in source, the representation will be rounded. Ignored if <= 0.
0N/A */
0N/A public final void set(boolean isNegative, long source, int maximumDigits) {
0N/A this.isNegative = isNegative;
0N/A
0N/A // This method does not expect a negative number. However,
0N/A // "source" can be a Long.MIN_VALUE (-9223372036854775808),
0N/A // if the number being formatted is a Long.MIN_VALUE. In that
0N/A // case, it will be formatted as -Long.MIN_VALUE, a number
0N/A // which is outside the legal range of a long, but which can
0N/A // be represented by DigitList.
0N/A if (source <= 0) {
0N/A if (source == Long.MIN_VALUE) {
0N/A decimalAt = count = MAX_COUNT;
0N/A System.arraycopy(LONG_MIN_REP, 0, digits, 0, count);
0N/A } else {
0N/A decimalAt = count = 0; // Values <= 0 format as zero
0N/A }
0N/A } else {
0N/A // Rewritten to improve performance. I used to call
0N/A // Long.toString(), which was about 4x slower than this code.
0N/A int left = MAX_COUNT;
0N/A int right;
0N/A while (source > 0) {
0N/A digits[--left] = (char)('0' + (source % 10));
0N/A source /= 10;
0N/A }
0N/A decimalAt = MAX_COUNT - left;
0N/A // Don't copy trailing zeros. We are guaranteed that there is at
0N/A // least one non-zero digit, so we don't have to check lower bounds.
0N/A for (right = MAX_COUNT - 1; digits[right] == '0'; --right)
0N/A ;
0N/A count = right - left + 1;
0N/A System.arraycopy(digits, left, digits, 0, count);
0N/A }
0N/A if (maximumDigits > 0) round(maximumDigits);
0N/A }
0N/A
0N/A /**
0N/A * Set the digit list to a representation of the given BigDecimal value.
0N/A * This method supports both fixed-point and exponential notation.
0N/A * @param isNegative Boolean value indicating whether the number is negative.
0N/A * @param source Value to be converted; must not be a value <= 0.
0N/A * @param maximumDigits The most fractional or total digits which should
0N/A * be converted.
0N/A * @param fixedPoint If true, then maximumDigits is the maximum
0N/A * fractional digits to be converted. If false, total digits.
0N/A */
0N/A final void set(boolean isNegative, BigDecimal source, int maximumDigits, boolean fixedPoint) {
0N/A String s = source.toString();
0N/A extendDigits(s.length());
0N/A
0N/A set(isNegative, s, maximumDigits, fixedPoint);
0N/A }
0N/A
0N/A /**
0N/A * Set the digit list to a representation of the given BigInteger value.
0N/A * @param isNegative Boolean value indicating whether the number is negative.
0N/A * @param source Value to be converted; must be >= 0.
0N/A * @param maximumDigits The most digits which should be converted.
0N/A * If maximumDigits is lower than the number of significant digits
0N/A * in source, the representation will be rounded. Ignored if <= 0.
0N/A */
0N/A final void set(boolean isNegative, BigInteger source, int maximumDigits) {
0N/A this.isNegative = isNegative;
0N/A String s = source.toString();
0N/A int len = s.length();
0N/A extendDigits(len);
0N/A s.getChars(0, len, digits, 0);
0N/A
0N/A decimalAt = len;
0N/A int right;
0N/A for (right = len - 1; right >= 0 && digits[right] == '0'; --right)
0N/A ;
0N/A count = right + 1;
0N/A
0N/A if (maximumDigits > 0) {
0N/A round(maximumDigits);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * equality test between two digit lists.
0N/A */
0N/A public boolean equals(Object obj) {
0N/A if (this == obj) // quick check
0N/A return true;
0N/A if (!(obj instanceof DigitList)) // (1) same object?
0N/A return false;
0N/A DigitList other = (DigitList) obj;
0N/A if (count != other.count ||
0N/A decimalAt != other.decimalAt)
0N/A return false;
0N/A for (int i = 0; i < count; i++)
0N/A if (digits[i] != other.digits[i])
0N/A return false;
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Generates the hash code for the digit list.
0N/A */
0N/A public int hashCode() {
0N/A int hashcode = decimalAt;
0N/A
0N/A for (int i = 0; i < count; i++) {
0N/A hashcode = hashcode * 37 + digits[i];
0N/A }
0N/A
0N/A return hashcode;
0N/A }
0N/A
0N/A /**
0N/A * Creates a copy of this object.
0N/A * @return a clone of this instance.
0N/A */
0N/A public Object clone() {
0N/A try {
0N/A DigitList other = (DigitList) super.clone();
0N/A char[] newDigits = new char[digits.length];
0N/A System.arraycopy(digits, 0, newDigits, 0, digits.length);
0N/A other.digits = newDigits;
0N/A other.tempBuffer = null;
0N/A return other;
0N/A } catch (CloneNotSupportedException e) {
0N/A throw new InternalError();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns true if this DigitList represents Long.MIN_VALUE;
0N/A * false, otherwise. This is required so that getLong() works.
0N/A */
0N/A private boolean isLongMIN_VALUE() {
0N/A if (decimalAt != count || count != MAX_COUNT) {
0N/A return false;
0N/A }
0N/A
0N/A for (int i = 0; i < count; ++i) {
0N/A if (digits[i] != LONG_MIN_REP[i]) return false;
0N/A }
0N/A
0N/A return true;
0N/A }
0N/A
0N/A private static final int parseInt(char[] str, int offset, int strLen) {
0N/A char c;
0N/A boolean positive = true;
0N/A if ((c = str[offset]) == '-') {
0N/A positive = false;
0N/A offset++;
0N/A } else if (c == '+') {
0N/A offset++;
0N/A }
0N/A
0N/A int value = 0;
0N/A while (offset < strLen) {
0N/A c = str[offset++];
0N/A if (c >= '0' && c <= '9') {
0N/A value = value * 10 + (c - '0');
0N/A } else {
0N/A break;
0N/A }
0N/A }
0N/A return positive ? value : -value;
0N/A }
0N/A
0N/A // The digit part of -9223372036854775808L
0N/A private static final char[] LONG_MIN_REP = "9223372036854775808".toCharArray();
0N/A
0N/A public String toString() {
0N/A if (isZero()) {
0N/A return "0";
0N/A }
0N/A StringBuffer buf = getStringBuffer();
0N/A buf.append("0.");
0N/A buf.append(digits, 0, count);
0N/A buf.append("x10^");
0N/A buf.append(decimalAt);
0N/A return buf.toString();
0N/A }
0N/A
0N/A private StringBuffer tempBuffer;
0N/A
0N/A private StringBuffer getStringBuffer() {
0N/A if (tempBuffer == null) {
0N/A tempBuffer = new StringBuffer(MAX_COUNT);
0N/A } else {
0N/A tempBuffer.setLength(0);
0N/A }
0N/A return tempBuffer;
0N/A }
0N/A
0N/A private void extendDigits(int len) {
0N/A if (len > digits.length) {
0N/A digits = new char[len];
0N/A }
0N/A }
0N/A
0N/A private final char[] getDataChars(int length) {
0N/A if (data == null || data.length < length) {
0N/A data = new char[length];
0N/A }
0N/A return data;
0N/A }
0N/A}