Package com.ibm.icu.impl.number
Class DecimalQuantity_DualStorageBCD
java.lang.Object
com.ibm.icu.impl.number.DecimalQuantity_AbstractBCD
com.ibm.icu.impl.number.DecimalQuantity_DualStorageBCD
- All Implemented Interfaces:
DecimalQuantity
,PluralRules.IFixedDecimal
A DecimalQuantity with internal storage as a 64-bit BCD, with fallback to a byte array for numbers
that don't fit into the standard BCD.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
The BCD of the 16 digits of the number represented by this object.private long
private boolean
Fields inherited from class com.ibm.icu.impl.number.DecimalQuantity_AbstractBCD
explicitExactDouble, exponent, flags, INFINITY_FLAG, INT64_BCD, isApproximate, lReqPos, NAN_FLAG, NEGATIVE_FLAG, origDelta, origDouble, precision, rReqPos, scale
-
Constructor Summary
ConstructorsConstructorDescriptionDecimalQuantity_DualStorageBCD
(double input) DecimalQuantity_DualStorageBCD
(int input) DecimalQuantity_DualStorageBCD
(long input) DecimalQuantity_DualStorageBCD
(Number number) -
Method Summary
Modifier and TypeMethodDescriptionprotected BigDecimal
Returns a BigDecimal encoding the internal BCD value.Deprecated.This API is for ICU internal use only.protected void
compact()
Removes trailing zeros from the BCD (adjusting the scale as required) and then computes the precision.protected void
copyBcdFrom
(DecimalQuantity _other) Like clone, but without the restrictions of the Cloneable interface clone.private void
Ensure that a byte array of at least 40 digits is allocated.private void
ensureCapacity
(int capacity) static DecimalQuantity
fromExponentString
(String num) Returns a DecimalQuantity after parsing the input string.protected byte
getDigitPos
(int position) Returns a single digit from the BCD list.private static int
getVisibleFractionCount
(String value) boolean
Deprecated.This API is ICU internal only.int
protected void
popFromLeft
(int numDigits) Directly removes digits from the front of the BCD list.protected void
Sets the internal BCD state to represent the value in the given BigInteger.protected void
readIntToBcd
(int n) Sets the internal BCD state to represent the value in the given int.protected void
readLongToBcd
(long n) Sets the internal BCD state to represent the value in the given long.protected void
Sets the internal representation to zero.protected void
setDigitPos
(int position, byte value) Sets the digit in the BCD list.protected void
shiftLeft
(int numDigits) Adds zeros to the end of the BCD list.protected void
shiftRight
(int numDigits) Removes digits from the end of the BCD list.private void
Switches the internal storage mechanism between the 64-bit long and the byte array.private String
toString()
Methods inherited from class com.ibm.icu.impl.number.DecimalQuantity_AbstractBCD
adjustExponent, adjustMagnitude, appendDigit, applyMaxInteger, clear, copyFrom, equals, fitsInLong, getDigit, getExponent, getLowerDisplayMagnitude, getMagnitude, getPluralOperand, getPositionFingerprint, getStandardPlural, getUpperDisplayMagnitude, isHasIntegerValue, isInfinite, isNaN, isNegative, isZeroish, multiplyBy, negate, populateUFieldPosition, resetExponent, roundToIncrement, roundToInfinity, roundToMagnitude, roundToNickel, setMinFraction, setMinInteger, setToBigDecimal, setToBigInteger, setToDouble, setToInt, setToLong, signum, toBigDecimal, toDouble, toExponentString, toFractionLong, toLong, toPlainString, toPlainString, toScientificString, toScientificString, truncate
-
Field Details
-
bcdBytes
private byte[] bcdBytesThe BCD of the 16 digits of the number represented by this object. Every 4 bits of the long map to one digit. For example, the number "12345" in BCD is "0x12345".Whenever bcd changes internally,
compact()
must be called, except in special cases like setting the digit to zero. -
bcdLong
private long bcdLong -
usingBytes
private boolean usingBytes
-
-
Constructor Details
-
DecimalQuantity_DualStorageBCD
public DecimalQuantity_DualStorageBCD() -
DecimalQuantity_DualStorageBCD
public DecimalQuantity_DualStorageBCD(long input) -
DecimalQuantity_DualStorageBCD
public DecimalQuantity_DualStorageBCD(int input) -
DecimalQuantity_DualStorageBCD
public DecimalQuantity_DualStorageBCD(double input) -
DecimalQuantity_DualStorageBCD
-
DecimalQuantity_DualStorageBCD
-
DecimalQuantity_DualStorageBCD
-
DecimalQuantity_DualStorageBCD
-
-
Method Details
-
maxRepresentableDigits
public int maxRepresentableDigits() -
createCopy
Description copied from interface:DecimalQuantity
Like clone, but without the restrictions of the Cloneable interface clone.- Returns:
- A copy of this instance which can be mutated without affecting this instance.
-
fromExponentString
Returns a DecimalQuantity after parsing the input string.- Parameters:
s
- The String to parse
-
getVisibleFractionCount
-
getDigitPos
protected byte getDigitPos(int position) Description copied from class:DecimalQuantity_AbstractBCD
Returns a single digit from the BCD list. No internal state is changed by calling this method.- Specified by:
getDigitPos
in classDecimalQuantity_AbstractBCD
- Parameters:
position
- The position of the digit to pop, counted in BCD units from the least significant digit. If outside the range supported by the implementation, zero is returned.- Returns:
- The digit at the specified location.
-
setDigitPos
protected void setDigitPos(int position, byte value) Description copied from class:DecimalQuantity_AbstractBCD
Sets the digit in the BCD list. This method only sets the digit; it is the caller's responsibility to callDecimalQuantity_AbstractBCD.compact()
after setting the digit, and to ensure that the precision field is updated to reflect the correct number of digits if a nonzero digit is added to the decimal.- Specified by:
setDigitPos
in classDecimalQuantity_AbstractBCD
- Parameters:
position
- The position of the digit to pop, counted in BCD units from the least significant digit. If outside the range supported by the implementation, an AssertionError is thrown.value
- The digit to set at the specified location.
-
shiftLeft
protected void shiftLeft(int numDigits) Description copied from class:DecimalQuantity_AbstractBCD
Adds zeros to the end of the BCD list. This will result in an invalid BCD representation; it is the caller's responsibility to do further manipulation and then callDecimalQuantity_AbstractBCD.compact()
.- Specified by:
shiftLeft
in classDecimalQuantity_AbstractBCD
- Parameters:
numDigits
- The number of zeros to add.
-
shiftRight
protected void shiftRight(int numDigits) Description copied from class:DecimalQuantity_AbstractBCD
Removes digits from the end of the BCD list. This may result in an invalid BCD representation; it is the caller's responsibility to follow-up with a call toDecimalQuantity_AbstractBCD.compact()
.- Specified by:
shiftRight
in classDecimalQuantity_AbstractBCD
- Parameters:
numDigits
- The number of digits to remove.
-
popFromLeft
protected void popFromLeft(int numDigits) Description copied from class:DecimalQuantity_AbstractBCD
Directly removes digits from the front of the BCD list. Updates precision. CAUTION: it is the caller's responsibility to callDecimalQuantity_AbstractBCD.compact()
after this method.- Specified by:
popFromLeft
in classDecimalQuantity_AbstractBCD
-
setBcdToZero
protected void setBcdToZero()Description copied from class:DecimalQuantity_AbstractBCD
Sets the internal representation to zero. Clears any values stored in scale, precision, hasDouble, origDouble, origDelta, exponent, and BCD data.- Specified by:
setBcdToZero
in classDecimalQuantity_AbstractBCD
-
readIntToBcd
protected void readIntToBcd(int n) Description copied from class:DecimalQuantity_AbstractBCD
Sets the internal BCD state to represent the value in the given int. The int is guaranteed to be either positive. The internal state is guaranteed to be empty when this method is called.- Specified by:
readIntToBcd
in classDecimalQuantity_AbstractBCD
-
readLongToBcd
protected void readLongToBcd(long n) Description copied from class:DecimalQuantity_AbstractBCD
Sets the internal BCD state to represent the value in the given long. The long is guaranteed to be either positive. The internal state is guaranteed to be empty when this method is called.- Specified by:
readLongToBcd
in classDecimalQuantity_AbstractBCD
-
readBigIntegerToBcd
Description copied from class:DecimalQuantity_AbstractBCD
Sets the internal BCD state to represent the value in the given BigInteger. The BigInteger is guaranteed to be positive, and it is guaranteed to be larger than Long.MAX_VALUE. The internal state is guaranteed to be empty when this method is called.- Specified by:
readBigIntegerToBcd
in classDecimalQuantity_AbstractBCD
-
bcdToBigDecimal
Description copied from class:DecimalQuantity_AbstractBCD
Returns a BigDecimal encoding the internal BCD value.- Specified by:
bcdToBigDecimal
in classDecimalQuantity_AbstractBCD
- Returns:
- A BigDecimal representation of the internal BCD.
-
compact
protected void compact()Description copied from class:DecimalQuantity_AbstractBCD
Removes trailing zeros from the BCD (adjusting the scale as required) and then computes the precision. The precision is the number of digits in the number up through the greatest nonzero digit.This method must always be called when bcd changes in order for assumptions to be correct in methods like
DecimalQuantity_AbstractBCD.fractionCount()
.- Specified by:
compact
in classDecimalQuantity_AbstractBCD
-
ensureCapacity
private void ensureCapacity()Ensure that a byte array of at least 40 digits is allocated. -
ensureCapacity
private void ensureCapacity(int capacity) -
switchStorage
private void switchStorage()Switches the internal storage mechanism between the 64-bit long and the byte array. -
copyBcdFrom
- Specified by:
copyBcdFrom
in classDecimalQuantity_AbstractBCD
-
checkHealth
Deprecated.This API is for ICU internal use only.Checks whether the bytes stored in this instance are all valid. For internal unit testing only.- Returns:
- An error message if this instance is invalid, or null if this instance is healthy.
-
isUsingBytes
Deprecated.This API is ICU internal only.Checks whether thisDecimalQuantity_DualStorageBCD
is using its internal byte array storage mechanism.- Returns:
- true if an internal byte array is being used; false if a long is being used.
-
toString
-
toNumberString
-