Package java.math

Examples of java.math.BigInteger.bitCount()


            n = ((Fixnum)arg).getBigInteger();
        else if (arg instanceof Bignum)
            n = ((Bignum)arg).getValue();
        else
            throw new ConditionThrowable(new TypeError(arg, "integer"));
        return new Fixnum(n.bitCount());
    }

    private static final logcount LOGCOUNT = new logcount();
}
View Full Code Here


    }

    public static UnsignedLong valueOf(final String value)
    {
        BigInteger bigInt = new BigInteger(value);
        if(bigInt.signum() == -1 || bigInt.bitCount()>64)
        {
            throw new NumberFormatException("Value \""+value+"\" lies outside the range [" + 0L + "- 2^64).");
        }
        else if(bigInt.compareTo(LONG_MAX_VALUE)>=0)
        {
View Full Code Here

      /**
       * computes the Hamming distance between B an C
       */
       public final int distance(BigInteger B,BigInteger C) {
          BigInteger D=B.xor(C);
          return D.bitCount();
       }
}
View Full Code Here

                }
                else {
                    if (bd.compareTo(BigDecimal.ZERO)<0)
                        bi=bi.subtract(BigInteger.ONE);
                }
                int biBitCount=bi.bitCount();
                if (biBitCount<=32)
                    return bi.intValue();
                else if (biBitCount<=64)
                    return bi.longValue();
                else
View Full Code Here

                }
                else {
                    if (numerator.compareTo(BigDecimal.ZERO)<0)
                        quotient=quotient.subtract(BigInteger.ONE);
                }
                int quotientBitCount=quotient.bitCount();
                if (quotientBitCount<=32)
                    return quotient.intValue();
                else if (quotientBitCount<=64)
                    return quotient.longValue();
                else
View Full Code Here

        System.out.println(" BitCount:   " + _value.bitCount());
        System.out.println(" BitLength   " + _value.bitLength());

        BigInteger j = _value.abs();
        System.out.println(" ABS value   " + j.toString(2));
        System.out.println(" ABS bit count:  " + j.bitCount());
        System.out.println(" ABD bitLength:  " + j.bitLength());
        System.out.println(" Max value:  "
                + getPrecision().findMaximum().doubleValue());
        System.out.println(" Min value:  "
                + getPrecision().findMinimum().doubleValue());
View Full Code Here

  @GwtIncompatible("java.math.BigInteger")
  public void testIsPowerOfTwo() {
    for (int x : ALL_INTEGER_CANDIDATES) {
      // Checks for a single bit set.
      BigInteger bigX = BigInteger.valueOf(x);
      boolean expected = (bigX.signum() > 0) && (bigX.bitCount() == 1);
      assertEquals(expected, IntMath.isPowerOfTwo(x));
    }
  }

  public void testLog2ZeroAlwaysThrows() {
View Full Code Here

  @GwtIncompatible("java.math.BigInteger")
  public void testIsPowerOfTwo() {
    for (long x : ALL_LONG_CANDIDATES) {
      // Checks for a single bit set.
      BigInteger bigX = BigInteger.valueOf(x);
      boolean expected = (bigX.signum() > 0) && (bigX.bitCount() == 1);
      assertEquals(expected, LongMath.isPowerOfTwo(x));
    }
  }

  public void testLog2ZeroAlwaysThrows() {
View Full Code Here

    }

    public static UnsignedLong valueOf(final String value)
    {
        BigInteger bigInt = new BigInteger(value);
        if(bigInt.signum() == -1 || bigInt.bitCount()>64)
        {
            throw new NumberFormatException("Value \""+value+"\" lies outside the range [" + 0L + "- 2^64).");
        }
        else if(bigInt.compareTo(LONG_MAX_VALUE)>=0)
        {
View Full Code Here

    }

    public static UnsignedLong valueOf(final String value)
    {
        BigInteger bigInt = new BigInteger(value);
        if(bigInt.signum() == -1 || bigInt.bitCount()>64)
        {
            throw new NumberFormatException("Value \""+value+"\" lies outside the range [" + 0L + "- 2^64).");
        }
        else if(bigInt.compareTo(LONG_MAX_VALUE)>=0)
        {
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.