Package sun.misc

Class FDBigInteger


  • public class FDBigInteger
    extends Object
    A simple big integer package specifically for floating point base conversion.
    • Constructor Detail

      • FDBigInteger

        public FDBigInteger​(long lValue,
                            char[] digits,
                            int kDigits,
                            int nDigits)
        Constructs an FDBigInteger from a starting value and some decimal digits.
        Parameters:
        lValue - The starting value.
        digits - The decimal digits.
        kDigits - The initial index into digits.
        nDigits - The final index into digits.
    • Method Detail

      • valueOfPow52

        public static FDBigInteger valueOfPow52​(int p5,
                                                int p2)
        Returns an FDBigInteger with the numerical value 5p5 * 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 an FDBigInteger with the numerical value value * 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 the FDBigIntger. 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 this FDBigInteger to the left. The shift is performed in-place unless the FDBigInteger is immutable in which case a new instance of FDBigInteger is returned.
        Parameters:
        shift - The number of bits to shift left.
        Returns:
        The shifted FDBigInteger.
      • quoRemIteration

        public int quoRemIteration​(FDBigInteger S)
                            throws IllegalArgumentException
        Computes
         q = (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 this FDBigInteger.
        Returns:
        q = (int)(this / S).
        Throws:
        IllegalArgumentException
      • multBy10

        public FDBigInteger multBy10()
        Multiplies this FDBigInteger by 10. The operation will be performed in place unless the FDBigInteger is immutable in which case a new FDBigInteger will be returned.
        Returns:
        The FDBigInteger multiplied by 10.
      • multByPow52

        public FDBigInteger multByPow52​(int p5,
                                        int p2)
        Multiplies this FDBigInteger by 5p5 * 2p2. The operation will be performed in place if possible, otherwise a new FDBigInteger will 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 supplied FDBigInteger subtrahend from this FDBigInteger. Assert that the result is positive. If the subtrahend is immutable, store the result in this(minuend). If this(minuend) is immutable a new FDBigInteger is created.
        Parameters:
        subtrahend - The FDBigInteger to be subtracted.
        Returns:
        This FDBigInteger less the subtrahend.
      • rightInplaceSub

        public FDBigInteger rightInplaceSub​(FDBigInteger subtrahend)
        Subtracts the supplied FDBigInteger subtrahend from this FDBigInteger. Assert that the result is positive. If the this(minuend) is immutable, store the result in subtrahend. If subtrahend is immutable a new FDBigInteger is created.
        Parameters:
        subtrahend - The FDBigInteger to be subtracted.
        Returns:
        This FDBigInteger less the subtrahend.
      • cmp

        public int cmp​(FDBigInteger other)
        Compares the parameter with this FDBigInteger. Returns an integer accordingly as:
         >0: this > other
          0: this == other
         <0: this < other
         
        Parameters:
        other - The FDBigInteger to 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 this FDBigInteger with 5p5 * 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 this FDBigInteger with x + 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 this FDBigInteger immutable.
      • toHexString

        public String toHexString()
        Converts this FDBigInteger to a hexadecimal string.
        Returns:
        The hexadecimal string representation.
      • toBigInteger

        public BigInteger toBigInteger()
        Converts this FDBigInteger to a BigInteger.
        Returns:
        The BigInteger representation.