Package java.math

Examples of java.math.BigInteger.negate()


    }
    // 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


    System.arraycopy(buf, offset, bytes, 0, len);
   
    BigInteger big = new BigInteger(bytes);
   
    if (negative) {
      big = big.negate();
    }
    return big;
  }

  public static void longToBytes(long v, byte[] buf, int offset) {
View Full Code Here

    System.arraycopy(buf, offset, bytes, 0, len);
   
    BigInteger big = new BigInteger(bytes);
   
    if (negative) {
      big = big.negate();
    }
    return big;
  }

  public static void longToBytes(long v, byte[] buf, int offset) {
View Full Code Here

            if (z.compareTo(BigInteger.valueOf(0)) <= 0) {
                // Handle negative modulo's specially
                /*if (z.compareTo(BigInteger.valueOf(0)) == 0) {
                  throw Py.ValueError("pow(x, y, z) with z == 0");
                  }*/
                y = value.modPow(y, z.negate());
                if (y.compareTo(BigInteger.valueOf(0)) > 0) {
                    return Py.newLong(z.add(y));
                } else {
                    return Py.newLong(y);
                }
View Full Code Here

            radix = 8;
            pos ++;
        } // default is to treat as decimal

        final BigInteger value = new BigInteger(str.substring(pos), radix);
        return negate ? value.negate() : value;
    }

    /**
     * <p>Convert a <code>String</code> to a <code>BigDecimal</code>.</p>
     *
 
View Full Code Here

    } else {
      BigInteger val = new BigInteger(sb.toString());

      if(negative) {
        val = val.negate();
      }

      return automaton.add(new Automaton.Int(val));
    }
  }
View Full Code Here

    else if((n = m.group(7)) != null)
      radix = Integer.parseInt(m.group(6));
    if(n == null)
      return null;
    BigInteger bn = new BigInteger(n, radix);
    return Numbers.reduce(negate ? bn.negate() : bn);
    }
  m = floatPat.matcher(s);
  if(m.matches())
    {
    if(m.group(4) != null)
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);
        }
        m = floatPat.matcher(s);
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

                    return num;
                }
            } else if (num.getInternalN() instanceof PyLong) {
                BigInteger v = ((PyLong)num.getInternalN()).getValue();
                if (v.compareTo(BigInteger.ZERO) == 1) {
                    num.setN(new PyLong(v.negate()));
                    return num;
                }
            } else if (num.getInternalN() instanceof PyFloat) {
                double v = ((PyFloat)num.getInternalN()).getValue();
                if (v >= 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.