/** * <p> * Compares this object to another based on size. * </p> * * @param object * the object to compare to, must not be <code>null</code>. * @return -1 if this is less than {@code object}, +1 if this is greater * than {@code object}, 0 if they are equal. * @see java.lang.Comparable#compareTo(java.lang.Object) */ public int compareTo(final BigFraction object) { int lhsSigNum = numerator.signum(); int rhsSigNum = object.numerator.signum(); if (lhsSigNum != rhsSigNum) { return (lhsSigNum > rhsSigNum) ? 1 : -1; } if (lhsSigNum == 0) { return 0; } BigInteger nOd = numerator.multiply(object.denominator); BigInteger dOn = denominator.multiply(object.numerator); return nOd.compareTo(dOn); }
BigInteger toSkip = len.add(BigInteger.valueOf(DWORD - suspectLocalFileHeader.length - APK_SIGNING_BLOCK_MAGIC.length)); byte[] magic = new byte[APK_SIGNING_BLOCK_MAGIC.length]; if (toSkip.signum() < 0) { while (toSkip.compareTo(LONG_MAX) > 0) { realSkip(Long.MAX_VALUE); toSkip = toSkip.add(LONG_MAX.negate());
if (remainder.signum() == 0) { return new BigDecimal(quotient, scale); int sign = scaledDividend.signum() * scaledDivisor.signum(); int compRem; // 'compare to remainder' if(scaledDivisor.bitLength() < 63) { // 63 in order to avoid out of long after *2 long rem = remainder.longValue(); long divisor = scaledDivisor.longValue(); compRem = remainder.abs().shiftLeftOneBit().compareTo(scaledDivisor.abs()); compRem = roundingBehavior(quotient.testBit(0) ? 1 : 0, sign * (5 + compRem), roundingMode); if(quotient.bitLength() < 63) { return valueOf(quotient.longValue() + compRem,scale); quotient = quotient.add(BigInteger.valueOf(compRem)); return new BigDecimal(quotient, scale);
if (this.a.signum() < 0 || this.a.compareTo(p) >= 0) { throw new IllegalArgumentException("the a is not in the field"); if (this.b.signum() < 0 || this.b.compareTo(p) >= 0) { throw new IllegalArgumentException("the b is not in the field"); if (!(this.a.bitLength() <= fieldSizeInBits)) { throw new IllegalArgumentException("the a is not in the field"); if (!(this.b.bitLength() <= fieldSizeInBits)) { throw new IllegalArgumentException("the b is not in the field");
/** * Power of a BigInteger to a BigInteger certain exponent. Called by the '**' operator. * * @param self a BigInteger * @param exponent a BigInteger exponent * @return a BigInteger to the power of a the exponent * @since 2.3.8 */ public static BigInteger power(BigInteger self, BigInteger exponent) { if ((exponent.signum() >= 0) && (exponent.compareTo(BI_INT_MAX) <= 0)) { return self.pow(exponent.intValue()); } else { return BigDecimal.valueOf(Math.pow(self.doubleValue(), exponent.doubleValue())).toBigInteger(); } }
/** * JDK8 Long.toUnsignedString was too complex to backport. Go for a slow version relying on * BigInteger */ // https://stackoverflow.com/questions/7031198/java-signed-long-to-unsigned-long-string static String toUnsignedString(long l) { BigInteger b = BigInteger.valueOf(l); if (b.signum() < 0) { b = b.add(TWO_64); } return b.toString(); } }
/** * Returns a {@code UnsignedInteger} representing the same value as the specified {@link * BigInteger}. This is the inverse operation of {@link #bigIntegerValue()}. * * @throws IllegalArgumentException if {@code value} is negative or {@code value >= 2^32} */ public static UnsignedInteger valueOf(BigInteger value) { checkNotNull(value); checkArgument( value.signum() >= 0 && value.bitLength() <= Integer.SIZE, "value (%s) is outside the range for an unsigned integer value", value); return fromIntBits(value.intValue()); }
if(denominator.signum() < 0) return new BigFraction(numerator.multiply(f.denominator).add(denominator.multiply(f.numerator)), denominator.multiply(f.denominator)); return new BigFraction(numerator.add(denominator.multiply(b)), denominator, true); return numerator.signum(); return numerator.compareTo(f.numerator); return numerator.multiply(f.denominator).compareTo(denominator.multiply(f.numerator)); int precision = Math.max(numerator.bitLength(), denominator.bitLength()); precision = (int)Math.ceil(precision / LG10); if(denominator.signum() < 0)
n = p.bitLength(); if (p.compareTo(BigInteger.valueOf(1)) != 1 || n < 512 || n > 1024 || (n & 077) != 0) { throw new InvalidKeyException("bad p"); if (q.signum() != 1 && q.bitLength() != 160) { throw new InvalidKeyException("bad q"); if (x.signum() != 1 || x.compareTo(q) != -1) { throw new InvalidKeyException("x <= 0 || x >= q");
if (denominator.signum() == 0) { throw new IllegalArgumentException("denominator is zero"); if (numerator.signum() == 0) { return ZERO; if (denominator.signum() < 0) { numerator = numerator.negate(); denominator = denominator.negate(); if (numerator.signum() != o.numerator.signum()) { return numerator.signum() - o.numerator.signum(); } else { if (o.numerator.signum() == 0) { return this; } else if (numerator.signum() == 0) { return o; } else if (denominator.equals(o.denominator)) { return new BigRational(numerator.add(o.numerator), denominator); } else { return canonical(numerator.multiply(o.denominator).add(o.numerator.multiply(denominator)), denominator.multiply(o.denominator), true); if (numerator.signum() == 0 || o.numerator.signum( )== 0) { return ZERO; } else if (numerator.equals(o.denominator)) { public boolean isInteger() { return numerator.signum() == 0 || denominator.equals(BigInteger.ONE); } public BigRational negate() { return new BigRational(numerator.negate(), denominator); }
@GwtIncompatible // TODO public void testSqrtCeiling() { for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) { for (RoundingMode mode : asList(CEILING, UP)) { BigInteger result = BigIntegerMath.sqrt(x, mode); assertTrue(result.compareTo(ZERO) > 0); assertTrue(result.pow(2).compareTo(x) >= 0); assertTrue(result.signum() == 0 || result.subtract(ONE).pow(2).compareTo(x) < 0); } } }
/** * Returns a {@code UnsignedLong} representing the same value as the specified {@code BigInteger}. * This is the inverse operation of {@link #bigIntegerValue()}. * * @throws IllegalArgumentException if {@code value} is negative or {@code value >= 2^64} */ @CanIgnoreReturnValue public static UnsignedLong valueOf(BigInteger value) { checkNotNull(value); checkArgument( value.signum() >= 0 && value.bitLength() <= Long.SIZE, "value (%s) is outside the range for an unsigned long value", value); return fromLongBits(value.longValue()); }
n1 = p.bitLength(); if (p.compareTo(BigInteger.valueOf(1)) != 1 || n1 < 512 || n1 > 1024 || (n1 & 077) != 0) { throw new InvalidKeyException("bad p"); if (q.signum() != 1 || q.bitLength() != 160) { throw new InvalidKeyException("bad q"); if (y.signum() != 1) { throw new InvalidKeyException("y <= 0");
MathUtils.checkNotNull(num, LocalizedFormats.NUMERATOR); MathUtils.checkNotNull(den, LocalizedFormats.DENOMINATOR); if (den.signum() == 0) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); if (num.signum() == 0) { numerator = BigInteger.ZERO; denominator = BigInteger.ONE; if (BigInteger.ONE.compareTo(gcd) < 0) { num = num.divide(gcd); den = den.divide(gcd); if (den.signum() == -1) { num = num.negate(); den = den.negate();