/*
* @(#)DigitList.java 1.34 06/01/26
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
* (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
*
* The original version of this source code and documentation is copyrighted
* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
* materials are provided under terms of a License Agreement between Taligent
* and Sun. This technology is protected by multiple US and International
* patents. This notice and attribution to Taligent may not be removed.
* Taligent is a registered trademark of Taligent, Inc.
*
*/
package java.text;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
/**
* Digit List. Private to DecimalFormat.
* Handles the transcoding
* between numeric values and strings of characters. Only handles
* non-negative numbers. The division of labor between DigitList and
* DecimalFormat is that DigitList handles the radix 10 representation
* issues; DecimalFormat handles the locale-specific issues such as
* positive/negative, grouping, decimal point, currency, and so on.
*
* A DigitList is really a representation of a floating point value.
* It may be an integer value; we assume that a double has sufficient
* precision to represent all digits of a long.
*
* The DigitList representation consists of a string of characters,
* which are the digits radix 10, from '0' to '9'. It also has a radix
* 10 exponent associated with it. The value represented by a DigitList
* object can be computed by mulitplying the fraction f, where 0 <= f < 1,
* derived by placing all the digits of the list to the right of the
* decimal point, by 10^exponent.
*
* @see Locale
* @see Format
* @see NumberFormat
* @see DecimalFormat
* @see ChoiceFormat
* @see MessageFormat
* @version 1.34 01/26/06
* @author Mark Davis, Alan Liu
*/
final class DigitList implements Cloneable {
/**
* The maximum number of significant digits in an IEEE 754 double, that
* is, in a Java double. This must not be increased, or garbage digits
* will be generated, and should not be decreased, or accuracy will be lost.
*/
public static final int MAX_COUNT = 19; // == Long.toString(Long.MAX_VALUE).length()
/**
* These data members are intentionally public and can be set directly.
*
* The value represented is given by placing the decimal point before
* digits[decimalAt]. If decimalAt is < 0, then leading zeros between
* the decimal point and the first nonzero digit are implied. If decimalAt
* is > count, then trailing zeros between the digits[count-1] and the
* decimal point are implied.
*
* Equivalently, the represented value is given by f * 10^decimalAt. Here
* f is a value 0.1 <= f < 1 arrived at by placing the digits in Digits to
* the right of the decimal.
*
* DigitList is normalized, so if it is non-zero, figits[0] is non-zero. We
* don't allow denormalized numbers because our exponent is effectively of
* unlimited magnitude. The count value contains the number of significant
* digits present in digits[].
*
* Zero is represented by any DigitList with count == 0 or with each digits[i]
* for all i <= count == '0'.
*/
public int decimalAt = 0;
public int count = 0;
public char[] digits = new char[MAX_COUNT];
private char[] data;
private RoundingMode roundingMode = RoundingMode.HALF_EVEN;
private boolean isNegative = false;
/**
* Return true if the represented number is zero.
*/
boolean isZero() {
for (int i=0; i < count; ++i) {
if (digits[i] != '0') {
return false;
}
=1= |