Package java.math

Examples of java.math.BigInteger.bitLength()


     * pair in accordance with X9.62 section 5.2.1 pages 26, 27.
     */
    public AsymmetricCipherKeyPair generateKeyPair()
    {
    BigInteger n = params.getN();
    int        nBitLength = n.bitLength();
    BigInteger d;

    do
    {
      d = new BigInteger(nBitLength, random);
View Full Code Here


            } else if (BigDecimal.ONE.equals(x)) {
                writeByte((byte) (DECIMAL_0_1 + 1));
            } else {
                int scale = x.scale();
                BigInteger b = x.unscaledValue();
                int bits = b.bitLength();
                if (bits <= 63) {
                    if (scale == 0) {
                        writeByte((byte) DECIMAL_SMALL_0);
                        writeVarLong(b.longValue());
                    } else {
View Full Code Here

            } else if (BigDecimal.ONE.equals(x)) {
                return 1;
            }
            int scale = x.scale();
            BigInteger b = x.unscaledValue();
            int bits = b.bitLength();
            if (bits <= 63) {
                if (scale == 0) {
                    return 1 + getVarLongLen(b.longValue());
                }
                return 1 + getVarIntLen(scale) + getVarLongLen(b.longValue());
View Full Code Here

      BigDecimal x = null, e = null;              // initial x:  x0 ~ sqrt()
      BigDecimal v = null, g = null;              // initial v:  v0 = 1/(2*x)

      // Estimate the square root with the foremost 62 bits of squarD
      BigInteger bi = squarD.unscaledValue();     // bi and scale are a tandem
      int biLen = bi.bitLength();
      int shift = Math.max(0, biLen - BITS + (biLen%2 == 0 ? 0 : 1));   // even shift..
      bi = bi.shiftRight(shift);                  // ..floors to 62 or 63 bit BigInteger

      double root = Math.sqrt(bi.doubleValue());
      BigDecimal halfBack = new BigDecimal(BigInteger.ONE.shiftLeft(shift/2));
View Full Code Here

        * v0:  v = 1/(2*x)
        */
        if (num == Double.POSITIVE_INFINITY)       // d > 1.7E308
        {
            BigInteger bi = numberToBeSquareRooted.unscaledValue();
            int biLen = bi.bitLength();
            int biSqrtLen = biLen / 2;                // floors it too

            bi = bi.shiftRight(biSqrtLen);          // bad guess sqrt(d)
            iteration1 = new BigDecimal(bi);                 // x ~ sqrt(d)

View Full Code Here

                            "Argument to SQRT() function must not be negative");
                }
                BigInteger n = x.movePointRight(mc.getPrecision() << 1)
                        .toBigInteger();

                int bits = (n.bitLength() + 1) >> 1;
                BigInteger ix = n.shiftRight(bits);
                BigInteger ixPrev;

                do {
                    ixPrev = ix;
View Full Code Here

   
    // The output's mantissa will have 'precision' or fewer bits
    public BigFloat multiply(BigFloat other, int precision, boolean roundUp) {
      BigInteger man = mantissa.multiply(other.mantissa);
      int exp = exponent + other.exponent;
      int excess = man.bitLength() - precision;
      if (excess > 0) {
        if (roundUp) {
          BigInteger mask = BigInteger.ONE.shiftLeft(excess).subtract(BigInteger.ONE);
          if (!mask.and(man).equals(BigInteger.ZERO))
            man = man.add(BigInteger.ONE.shiftLeft(excess));
View Full Code Here

    Set<Long> numbers = new HashSet<Long>();
    long max = 0;
    for (int n = 0; n <= 50; n++) {
      for(int k = 0; k <= n; k++) {
        BigInteger x = Library.binomial(n, k);
        if (x.bitLength() >= 64)
          throw new AssertionError("Number too large to handle");
        numbers.add(x.longValue());
        max = Math.max(x.longValue(), max);
      }
    }
View Full Code Here

        }
       
        BigInteger norm = norm(mu, lambda);

        // Ceiling of log2 of the norm
        int log2Norm = norm.bitLength();

        // If length(TNAF) > 30, then length(TNAF) < log2Norm + 3.52
        int maxLength = log2Norm > 30 ? log2Norm + 4 : 34;

        // The array holding the TNAF
View Full Code Here

        }

        BigInteger norm = norm(mu, lambda);

        // Ceiling of log2 of the norm
        int log2Norm = norm.bitLength();

        // If length(TNAF) > 30, then length(TNAF) < log2Norm + 3.52
        int maxLength = log2Norm > 30 ? log2Norm + 4 + width : 34 + width;

        // The array holding the TNAF
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.