Package java.math

Examples of java.math.BigInteger.bitLength()


                + text);
          }
        }
      } else {
        if (isSigned) {
          if (bigValue.bitLength() > 63) {
            throw new NumberFormatException("Number out of range for 64-bit signed integer: "
                + text);
          }
        } else {
          if (bigValue.bitLength() > 64) {
View Full Code Here


          if (bigValue.bitLength() > 63) {
            throw new NumberFormatException("Number out of range for 64-bit signed integer: "
                + text);
          }
        } else {
          if (bigValue.bitLength() > 64) {
            throw new NumberFormatException("Number out of range for 64-bit unsigned integer: "
                + text);
          }
        }
      }
View Full Code Here

    Random prng = new Random();
    BigInteger bi;
    try
      {
        bi = new BigInteger(25, 80, prng);
        harness.check(bi.bitLength(), 25, "Constructed BigInteger MUST be 25-bit long");

        bi = new BigInteger(2, 80, prng);
        harness.check(bi.bitLength(), 2, "Constructed BigInteger MUST be 2-bit long");
        int val = bi.intValue();
        harness.check(val == 2 || val == 3, "Constructed BigInteger MUST be 2 or 3");
View Full Code Here

      {
        bi = new BigInteger(25, 80, prng);
        harness.check(bi.bitLength(), 25, "Constructed BigInteger MUST be 25-bit long");

        bi = new BigInteger(2, 80, prng);
        harness.check(bi.bitLength(), 2, "Constructed BigInteger MUST be 2-bit long");
        int val = bi.intValue();
        harness.check(val == 2 || val == 3, "Constructed BigInteger MUST be 2 or 3");
      }
    catch (Exception x)
      {
View Full Code Here

    try
      {
        for (int realNumBits, numBits = 8; numBits < 2048; numBits++)
          {
            bi = new BigInteger(numBits, prng);
            realNumBits = bi.bitLength();
            if (realNumBits > numBits)
              harness.fail("Constructed BigInteger has " + realNumBits
                          + " bits when it SHOULD be <= " + numBits);
          }
      }
View Full Code Here

         *
         * To determine which side of logFloor.5 the logarithm is, we compare x^2 to 2^(2 *
         * logFloor + 1).
         */
        BigInteger x2 = x.pow(2);
        int logX2Floor = x2.bitLength() - 1;
        return (logX2Floor < 2 * logFloor + 1) ? logFloor : logFloor + 1;

      default:
        throw new AssertionError();
    }
View Full Code Here

  }

  static double bigToDouble(BigInteger x) {
    // This is an extremely fast implementation of BigInteger.doubleValue().  JDK patch pending.
    BigInteger absX = x.abs();
    int exponent = absX.bitLength() - 1;
    // exponent == floor(log2(abs(x)))
    if (exponent < Long.SIZE - 1) {
      return x.longValue();
    } else if (exponent > MAX_DOUBLE_EXPONENT) {
      return x.signum() * Double.POSITIVE_INFINITY;
 
View Full Code Here

      }

      // Check bounds.
      if (!isLong) {
        if (isSigned) {
          if (bigValue.bitLength() > 31) {
            throw new NumberFormatException(
              "Number out of range for 32-bit signed integer: " + text);
          }
        } else {
          if (bigValue.bitLength() > 32) {
View Full Code Here

          if (bigValue.bitLength() > 31) {
            throw new NumberFormatException(
              "Number out of range for 32-bit signed integer: " + text);
          }
        } else {
          if (bigValue.bitLength() > 32) {
            throw new NumberFormatException(
              "Number out of range for 32-bit unsigned integer: " + text);
          }
        }
      } else {
View Full Code Here

              "Number out of range for 32-bit unsigned integer: " + text);
          }
        }
      } else {
        if (isSigned) {
          if (bigValue.bitLength() > 63) {
            throw new NumberFormatException(
              "Number out of range for 64-bit signed integer: " + text);
          }
        } else {
          if (bigValue.bitLength() > 64) {
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.