Package java.math

Examples of java.math.BigInteger.negate()


                digits[i] = input.readSignedByte();
        }

        BigInteger value = new BigInteger(digits);
        if (!positive) {
            value = value.negate();
        }

        RubyNumeric result = bignorm(input.getRuntime(), value);
        input.registerLinkTarget(result);
        return result;
View Full Code Here


                switch (getUnaryOp()) {
                    case Plus:
                        return constant;
                    case Minus:
                        return GoTypes.constant(GoTypeConstant.Kind.Integer, intValue.negate());
                    case Not:
                        return GoTypes.constant(GoTypeConstant.Kind.Integer, intValue.not());
                    case Xor:
                        return GoTypes.constant(GoTypeConstant.Kind.Integer, intValue.not());
                    default:
View Full Code Here

                case Int:
                case Char:
                    BigInteger intValue = (BigInteger) getData().second;
                    switch (op) {
                        case Minus:
                            setData(Pair.create(GoLiteral.Type.Int, intValue.negate()));
                            break;
                        case Xor:
                            BigInteger twoComplementValue = intValue.signum() == -1
                                    ? BigInteger.ONE.negate().xor(intValue)
                                    : BigInteger.ONE.shiftLeft(intValue.bitLength()).subtract(BigInteger.ONE).xor(intValue);
View Full Code Here

      radix = Integer.parseInt(m.group(6));
    if(n == null)
      return null;
    BigInteger bn = new BigInteger(n, radix);
    if(negate)
      bn = bn.negate();
    if(m.group(8) != null)
      return BigInt.fromBigInteger(bn);
    return bn.bitLength() < 64 ?
           Numbers.num(bn.longValue())
                               : BigInt.fromBigInteger(bn);
View Full Code Here

      }

      BigInteger bigInt = new BigInteger(md.digest());

      if (bigInt.compareTo(BigInteger.ZERO) < 0) {
        bigInt = bigInt.negate();
        return "-" + bigInt.toString(16);
      } else {
        return bigInt.toString(16);
      }
    } catch (Exception ioe) {
View Full Code Here

      }

      BigInteger bigInt = new BigInteger(md.digest());

      if (bigInt.compareTo(BigInteger.ZERO) < 0) {
        bigInt = bigInt.negate();
        return "-" + bigInt.toString(16);
      } else {
        return bigInt.toString(16);
      }
    } catch (Exception ioe) {
View Full Code Here

        0x62EB40FEF85AA9EBL * 2).negate().equals(
        BigInteger.valueOf(-0x62EB40FEF85AA9EBL * 2)));
    for (int i = 0; i < 200; i++) {
      BigInteger midbit = zero.setBit(i);
      BigInteger negate = midbit.negate();
      assertTrue("negate negate", negate.negate().equals(midbit));
      assertTrue("neg fails on bit " + i, midbit.negate().add(midbit)
          .equals(zero));
    }
  }

View Full Code Here

    }
  }

  private void testDivRanges(BigInteger i) {
    BigInteger bound = i.multiply(two);
    for (BigInteger j = bound.negate(); j.compareTo(bound) <= 0; j = j
        .add(i)) {
      BigInteger innerbound = j.add(two);
      BigInteger k = j.subtract(two);
      for (; k.compareTo(innerbound) <= 0; k = k.add(one)) {
                testDiv(k, i);
View Full Code Here

        } else if (val instanceof BigDecimal) {
            BigDecimal valueAsBigD = (BigDecimal) val;
            return valueAsBigD.negate();
        } else if (val instanceof BigInteger) {
            BigInteger valueAsBigI = (BigInteger) val;
            return valueAsBigI.negate();
        } else if (val instanceof Float) {
            float valueAsFloat = ((Float) val).floatValue();
            return new Float(-valueAsFloat);
        } else if (val instanceof Short) {
            short valueAsShort = ((Short) val).shortValue();
View Full Code Here

    }
    // convert back to a signed number
    boolean isNegative = result.testBit(0);
    if (isNegative) {
      result = result.add(BigInteger.ONE);
      result = result.negate();
    }
    result = result.shiftRight(1);
    return result;
  }
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.