Top Description Fields Constructors Methods
org.apache.poi.ss.util

pack-priv final Class NormalisedDecimal

extends Object
Class Inheritance
Imports
java.math.BigDecimal, .BigInteger

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:
  1. Comparison operations
  2. Conversions to text

This class does not handle negative numbers or zero.

The value of a NormalisedDecimal is given by
significand × 10decimalExponent
where:
significand = wholePart + fractionalPart / 224

Field Summary

Modifier and TypeField and Description
private final int
_fractionalPart

The fractional part of the significand.

private final int
_relativeDecimalExponent

The decimal exponent increased by one less than the digit count of _wholePart

private final long
_wholePart

The whole part of the significand (typically 15 digits).

private static final BigDecimal
private static final int
private static final int
EXPONENT_OFFSET

Number of powers of ten contained in the significand

private static final int
FRAC_HALF

the value of _fractionalPart that represents 0.5

private static final int
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
NormalisedDecimal(long wholePart, int fracPart, int decimalExponent)

Method Summary

Modifier and TypeMethod and Description
public int
compareNormalised(NormalisedDecimal other)

assumes both this and other are normalised

pack-priv BigInteger

Returns:

the significand as a fixed point number (with 24 fraction bits and 47-50 whole bits)
composeFrac
()

public static NormalisedDecimal
create(BigInteger frac, int binaryExponent)

public int

Returns:

the number of powers of 10 which have been extracted from the significand and binary exponent.
getDecimalExponent
()

private String
public BigDecimal
public String
public String
getSignificantDecimalDigitsLastDigitRounded()

Rounds the first whole digit position (considers only units digit, not frational part).

public ExpandedDouble

Returns:

a new NormalisedDecimal normalised to base 2 representation.
normaliseBaseTwo
()

Convert to an equivalent ExpandedDouble representation (binary frac and exponent).

public NormalisedDecimal
roundUnits()

Rounds at the digit with value 10decimalExponent

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_fractionalPartback to summary
private final int _fractionalPart

The fractional part of the significand. 24 bits (only top 14-17 bits significant): a value between 0x000000 and 0xFFFF80

_relativeDecimalExponentback to summary
private final int _relativeDecimalExponent

The decimal exponent increased by one less than the digit count of _wholePart

_wholePartback to summary
private final long _wholePart

The 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.

BD_2_POW_24back to summary
private static final BigDecimal BD_2_POW_24
C_2_POW_19back to summary
private static final int C_2_POW_19

219

EXPONENT_OFFSETback to summary
private static final int EXPONENT_OFFSET

Number of powers of ten contained in the significand

FRAC_HALFback to summary
private static final int FRAC_HALF

the value of _fractionalPart that represents 0.5

LOG_BASE_10_OF_2_TIMES_2_POW_20back to summary
private static final int LOG_BASE_10_OF_2_TIMES_2_POW_20

log10(2)×220

MAX_REP_WHOLE_PARTback to summary
private static final long MAX_REP_WHOLE_PART

1015

Constructor Detail

NormalisedDecimalback to summary
pack-priv NormalisedDecimal(long wholePart, int fracPart, int decimalExponent)

Method Detail

compareNormalisedback to summary
public int compareNormalised(NormalisedDecimal other)

assumes both this and other are normalised

composeFracback to summary
pack-priv BigInteger composeFrac()
Returns:BigInteger

the significand as a fixed point number (with 24 fraction bits and 47-50 whole bits)

createback to summary
public static NormalisedDecimal create(BigInteger frac, int binaryExponent)
Annotations
@SuppressWarnings:java:S128
getDecimalExponentback to summary
public int getDecimalExponent()
Returns:int

the number of powers of 10 which have been extracted from the significand and binary exponent.

getFractionalDigitsback to summary
private String getFractionalDigits()
getFractionalPartback to summary
public BigDecimal getFractionalPart()
getSignificantDecimalDigitsback to summary
public String getSignificantDecimalDigits()
getSignificantDecimalDigitsLastDigitRoundedback to summary
public String 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

normaliseBaseTwoback to summary
public ExpandedDouble normaliseBaseTwo()

Convert to an equivalent ExpandedDouble representation (binary frac and exponent). The resulting transformed object is easily converted to a 64 bit IEEE double:

The sign bit must be obtained from somewhere else.
Returns:ExpandedDouble

a new NormalisedDecimal normalised to base 2 representation.

roundUnitsback to summary
public NormalisedDecimal roundUnits()

Rounds at the digit with value 10decimalExponent

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override