Class NormalisedDecimal
java.lang.Object
org.xlsx4j.org.apache.poi.ss.util.NormalisedDecimal
Represents a transformation of a 64 bit IEEE double quantity having a decimal exponent and a
fixed point (15 decimal digit) significand. Some quirks of Excel's calculation behaviour are
simpler to reproduce with numeric quantities in this format. This class is currently used to
help:
significand × 10decimalExponent
where:
significand = wholePart + fractionalPart / 224
- Comparison operations
- Conversions to text
NormalisedDecimal is given bysignificand × 10decimalExponent
where:
significand = wholePart + fractionalPart / 224
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe fractional part of the significand.private final intThe decimal exponent increased by one less than the digit count of_wholePartprivate final longThe whole part of the significand (typically 15 digits).private static final BigDecimalprivate static final int219private static final intNumber of powers of ten contained in the significandprivate static final intthe value of_fractionalPartthat represents 0.5private static final intlog10(2)×220private static final long1015 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintassumes both this and other are normalised(package private) BigIntegerstatic NormalisedDecimalcreate(BigInteger frac, int binaryExponent) intprivate StringRounds the first whole digit position (considers only units digit, not frational part).Convert to an equivalentExpandedDoublerepresentation (binary frac and exponent).Rounds at the digit with value 10decimalExponenttoString()
-
Field Details
-
EXPONENT_OFFSET
private static final int EXPONENT_OFFSETNumber of powers of ten contained in the significand- See Also:
-
BD_2_POW_24
-
LOG_BASE_10_OF_2_TIMES_2_POW_20
private static final int LOG_BASE_10_OF_2_TIMES_2_POW_20log10(2)×220- See Also:
-
C_2_POW_19
private static final int C_2_POW_19219- See Also:
-
FRAC_HALF
private static final int FRAC_HALFthe value of_fractionalPartthat represents 0.5- See Also:
-
MAX_REP_WHOLE_PART
private static final long MAX_REP_WHOLE_PART1015- See Also:
-
_relativeDecimalExponent
private final int _relativeDecimalExponentThe decimal exponent increased by one less than the digit count of_wholePart -
_wholePart
private final long _wholePartThe whole part of the significand (typically 15 digits). 47-50 bits long (MSB may be anywhere from bit 46 to 49) LSB is units bit. -
_fractionalPart
private final int _fractionalPartThe fractional part of the significand. 24 bits (only top 14-17 bits significant): a value between 0x000000 and 0xFFFF80
-
-
Constructor Details
-
NormalisedDecimal
NormalisedDecimal(long wholePart, int fracPart, int decimalExponent)
-
-
Method Details
-
create
-
roundUnits
Rounds at the digit with value 10decimalExponent -
normaliseBaseTwo
Convert to an equivalentExpandedDoublerepresentation (binary frac and exponent). The resulting transformed object is easily converted to a 64 bit IEEE double:- bits 2-53 of the
#getSignificand()become the 52 bit 'fraction'. #getBinaryExponent()is biased by 1023 to give the 'exponent'.
- Returns:
- a new
NormalisedDecimalnormalised to base 2 representation.
- bits 2-53 of the
-
composeFrac
BigInteger composeFrac()- Returns:
- the significand as a fixed point number (with 24 fraction bits and 47-50 whole bits)
-
getSignificantDecimalDigits
-
getSignificantDecimalDigitsLastDigitRounded
Rounds the first whole digit position (considers only units digit, not frational part). Caller should check total digit count of result to see whether the rounding operation caused a carry out of the most significant digit -
getDecimalExponent
public int getDecimalExponent()- Returns:
- the number of powers of 10 which have been extracted from the significand and binary exponent.
-
compareNormalised
assumes both this and other are normalised -
getFractionalPart
-
getFractionalDigits
-
toString
-