Package sun.misc
Class FDBigInteger
- java.lang.Object
-
- sun.misc.FDBigInteger
-
public class FDBigInteger extends Object
A simple big integer package specifically for floating point base conversion.
-
-
Field Summary
Fields Modifier and Type Field Description static FDBigIntegerFIVEstatic FDBigIntegerONEstatic FDBigIntegerZERO
-
Constructor Summary
Constructors Constructor Description FDBigInteger(long lValue, char[] digits, int kDigits, int nDigits)Constructs anFDBigIntegerfrom a starting value and some decimal digits.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddAndCmp(FDBigInteger x, FDBigInteger y)Compares thisFDBigIntegerwithx + y.intcmp(FDBigInteger other)Compares the parameter with thisFDBigInteger.intcmpPow52(int p5, int p2)Compares thisFDBigIntegerwith5p5 * 2p2.intgetNormalizationBias()Retrieves the normalization bias of theFDBigIntger.FDBigIntegerleftInplaceSub(FDBigInteger subtrahend)Subtracts the suppliedFDBigIntegersubtrahend from thisFDBigInteger.FDBigIntegerleftShift(int shift)Shifts thisFDBigIntegerto the left.voidmakeImmutable()Makes thisFDBigIntegerimmutable.FDBigIntegermultBy10()Multiplies thisFDBigIntegerby 10.FDBigIntegermultByPow52(int p5, int p2)Multiplies thisFDBigIntegerby5p5 * 2p2.intquoRemIteration(FDBigInteger S)ComputesFDBigIntegerrightInplaceSub(FDBigInteger subtrahend)Subtracts the suppliedFDBigIntegersubtrahend from thisFDBigInteger.BigIntegertoBigInteger()Converts thisFDBigIntegerto aBigInteger.StringtoHexString()Converts thisFDBigIntegerto a hexadecimal string.static FDBigIntegervalueOfMulPow52(long value, int p5, int p2)Returns anFDBigIntegerwith the numerical valuevalue * 5p5 * 2p2.static FDBigIntegervalueOfPow52(int p5, int p2)Returns anFDBigIntegerwith the numerical value5p5 * 2p2.
-
-
-
Field Detail
-
ZERO
public static final FDBigInteger ZERO
-
ONE
public static final FDBigInteger ONE
-
FIVE
public static final FDBigInteger FIVE
-
-
Constructor Detail
-
FDBigInteger
public FDBigInteger(long lValue, char[] digits, int kDigits, int nDigits)Constructs anFDBigIntegerfrom a starting value and some decimal digits.- Parameters:
lValue- The starting value.digits- The decimal digits.kDigits- The initial index intodigits.nDigits- The final index intodigits.
-
-
Method Detail
-
valueOfPow52
public static FDBigInteger valueOfPow52(int p5, int p2)
Returns anFDBigIntegerwith the numerical value5p5 * 2p2.- Parameters:
p5- The exponent of the power-of-five factor.p2- The exponent of the power-of-two factor.- Returns:
5p5 * 2p2
-
valueOfMulPow52
public static FDBigInteger valueOfMulPow52(long value, int p5, int p2)
Returns anFDBigIntegerwith the numerical valuevalue * 5p5 * 2p2.- Parameters:
value- The constant factor.p5- The exponent of the power-of-five factor.p2- The exponent of the power-of-two factor.- Returns:
value * 5p5 * 2p2
-
getNormalizationBias
public int getNormalizationBias()
Retrieves the normalization bias of theFDBigIntger. The normalization bias is a left shift such that after it the highest word of the value will have the 4 highest bits equal to zero:(highestWord & 0xf0000000) == 0, but the next bit should be 1(highestWord & 0x08000000) != 0.- Returns:
- The normalization bias.
-
leftShift
public FDBigInteger leftShift(int shift)
Shifts thisFDBigIntegerto the left. The shift is performed in-place unless theFDBigIntegeris immutable in which case a new instance ofFDBigIntegeris returned.- Parameters:
shift- The number of bits to shift left.- Returns:
- The shifted
FDBigInteger.
-
quoRemIteration
public int quoRemIteration(FDBigInteger S) throws IllegalArgumentException
Computesq = (int)( this / S ) this = 10 * ( this mod S ) Return q.
This is the iteration step of digit development for output. We assume that S has been normalized, as above, and that "this" has been left-shifted accordingly. Also assumed, of course, is that the result, q, can be expressed as an integer, 0 <= q < 10.- Parameters:
S- The divisor of thisFDBigInteger.- Returns:
q = (int)(this / S).- Throws:
IllegalArgumentException
-
multBy10
public FDBigInteger multBy10()
Multiplies thisFDBigIntegerby 10. The operation will be performed in place unless theFDBigIntegeris immutable in which case a newFDBigIntegerwill be returned.- Returns:
- The
FDBigIntegermultiplied by 10.
-
multByPow52
public FDBigInteger multByPow52(int p5, int p2)
Multiplies thisFDBigIntegerby5p5 * 2p2. The operation will be performed in place if possible, otherwise a newFDBigIntegerwill be returned.- Parameters:
p5- The exponent of the power-of-five factor.p2- The exponent of the power-of-two factor.- Returns:
-
leftInplaceSub
public FDBigInteger leftInplaceSub(FDBigInteger subtrahend)
Subtracts the suppliedFDBigIntegersubtrahend from thisFDBigInteger. Assert that the result is positive. If the subtrahend is immutable, store the result in this(minuend). If this(minuend) is immutable a newFDBigIntegeris created.- Parameters:
subtrahend- TheFDBigIntegerto be subtracted.- Returns:
- This
FDBigIntegerless the subtrahend.
-
rightInplaceSub
public FDBigInteger rightInplaceSub(FDBigInteger subtrahend)
Subtracts the suppliedFDBigIntegersubtrahend from thisFDBigInteger. Assert that the result is positive. If the this(minuend) is immutable, store the result in subtrahend. If subtrahend is immutable a newFDBigIntegeris created.- Parameters:
subtrahend- TheFDBigIntegerto be subtracted.- Returns:
- This
FDBigIntegerless the subtrahend.
-
cmp
public int cmp(FDBigInteger other)
Compares the parameter with thisFDBigInteger. Returns an integer accordingly as:>0: this > other 0: this == other <0: this < other
- Parameters:
other- TheFDBigIntegerto compare.- Returns:
- A negative value, zero, or a positive value according to the result of the comparison.
-
cmpPow52
public int cmpPow52(int p5, int p2)Compares thisFDBigIntegerwith5p5 * 2p2. Returns an integer accordingly as:>0: this > other 0: this == other <0: this < other
- Parameters:
p5- The exponent of the power-of-five factor.p2- The exponent of the power-of-two factor.- Returns:
- A negative value, zero, or a positive value according to the result of the comparison.
-
addAndCmp
public int addAndCmp(FDBigInteger x, FDBigInteger y)
Compares thisFDBigIntegerwithx + y. Returns a value according to the comparison as:-1: this < x + y 0: this == x + y 1: this > x + y
- Parameters:
x- The first addend of the sum to compare.y- The second addend of the sum to compare.- Returns:
- -1, 0, or 1 according to the result of the comparison.
-
makeImmutable
public void makeImmutable()
Makes thisFDBigIntegerimmutable.
-
toHexString
public String toHexString()
Converts thisFDBigIntegerto a hexadecimal string.- Returns:
- The hexadecimal string representation.
-
toBigInteger
public BigInteger toBigInteger()
Converts thisFDBigIntegerto aBigInteger.- Returns:
- The
BigIntegerrepresentation.
-
-