Package java.math

Examples of java.math.BigInteger.negate()


        BigInteger x3 = m.pow(2).subtract(this.x.add(another.x))
            .mod(curve.p);
        // y3 = y2 + m (x3-x2)
        BigInteger y3 = another.y.add(
            m.multiply(x3.subtract(another.x))).mod(curve.p);
        return new Element(curve, x3, y3.negate());
      }
    }

    public Element slowmul(int num) {
      Element now = this;
View Full Code Here


      return BigInteger.valueOf((long) x);
    }
    int exponent = getExponent(x);
    long significand = getSignificand(x);
    BigInteger result = BigInteger.valueOf(significand).shiftLeft(exponent - SIGNIFICAND_BITS);
    return (x < 0) ? result.negate() : result;
  }

  /**
   * Returns {@code true} if {@code x} is exactly equal to {@code 2^k} for some finite integer
   * {@code k}.
View Full Code Here

   * Equivalent to calling randomPositiveBigInteger(numBits) and then flipping
   * the sign with 50% probability.
   */
  static BigInteger randomNonZeroBigInteger(int numBits) {
    BigInteger result = randomPositiveBigInteger(numBits);
    return RANDOM_SOURCE.nextBoolean() ? result : result.negate();
  }

  /**
   * Chooses a number in (-2^numBits, 2^numBits) at random, with density
   * concentrated in numbers of lower magnitude.
View Full Code Here

      return BigInteger.valueOf((long) x);
    }
    int exponent = getExponent(x);
    long significand = getSignificand(x);
    BigInteger result = BigInteger.valueOf(significand).shiftLeft(exponent - SIGNIFICAND_BITS);
    return (x < 0) ? result.negate() : result;
  }

  /**
   * Returns {@code true} if {@code x} is exactly equal to {@code 2^k} for some finite integer
   * {@code k}.
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

            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 if (val instanceof BigDecimal) {
            BigDecimal valueAsBigD = (BigDecimal) val;
            return valueAsBigD.negate();
        } else if (val instanceof BigInteger) {
            BigInteger valueAsBigI = (BigInteger) val;
            return valueAsBigI.negate();
        }
        throw new Exception("expression not a number");
    }
}
View Full Code Here

    {
      BinaryDecimal rbd = (BinaryDecimal) result;
     
      BigInteger bi = new BigInteger(data2c);
      // scale remains unchanged.
      rbd.data2c = bi.negate().toByteArray();
      rbd.sqlScale = sqlScale;
   
    }
     
    return result;
View Full Code Here

            exp = expSig * Long.parseLong(expSig < 0 ? invert(e, 0) : e);
            value = value.substring(3 + expSize);
        }
        BigInteger x = new BigInteger(value);
        int scale = (int) (value.length() - exp - 1);
        return new BigDecimal(sig < 0 ? x.negate() : x, scale);
    }
   
    private static String positiveDecimalToString(BigDecimal value) {
        StringBuilder buff = new StringBuilder();
        long exp = value.precision() - value.scale() - 1;
View Full Code Here

        }
      }
    } else {
      BigInteger bigValue = new BigInteger(numberText, radix);
      if (negative) {
        bigValue = bigValue.negate();
      }

      // Check bounds.
      if (!isLong) {
        if (isSigned) {
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.