当前位置: 首页>>代码示例>>Java>>正文


Java BigInteger.signum方法代码示例

本文整理汇总了Java中java.math.BigInteger.signum方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.signum方法的具体用法?Java BigInteger.signum怎么用?Java BigInteger.signum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.math.BigInteger的用法示例。


在下文中一共展示了BigInteger.signum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkValidity

import java.math.BigInteger; //导入方法依赖的package包/类
private static void checkValidity(ECField field, BigInteger c,
    String cName) {
    // can only perform check if field is ECFieldFp or ECFieldF2m.
    if (field instanceof ECFieldFp) {
        BigInteger p = ((ECFieldFp)field).getP();
        if (p.compareTo(c) != 1) {
            throw new IllegalArgumentException(cName + " is too large");
        } else if (c.signum() < 0) {
            throw new IllegalArgumentException(cName + " is negative");
        }
    } else if (field instanceof ECFieldF2m) {
        int m = ((ECFieldF2m)field).getM();
        if (c.bitLength() > m) {
            throw new IllegalArgumentException(cName + " is too large");
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:EllipticCurve.java

示例2: multiply

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Multiplies this <code>ECPoint</code> by the given number.
 * @param k The multiplicator.
 * @return <code>k * this</code>.
 */
public ECPoint multiply(BigInteger k)
{
    if (k.signum() < 0)
    {
        throw new IllegalArgumentException("The multiplicator cannot be negative");
    }

    if (this.isInfinity())
    {
        return this;
    }

    if (k.signum() == 0)
    {
        return this.curve.getInfinity();
    }

    assertECMultiplier();
    return this.multiplier.multiply(this, k, preCompInfo);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:26,代码来源:ECPoint.java

示例3: checkFirstComponent

import java.math.BigInteger; //导入方法依赖的package包/类
private static void checkFirstComponent(BigInteger first) throws IOException {
    if (first.signum() == -1 ||
            first.compareTo(BigInteger.valueOf(2)) == 1) {
        throw new IOException("ObjectIdentifier() -- " +
                "First oid component is invalid ");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:ObjectIdentifier.java

示例4: randomPositiveBigInteger

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Generates values in a distribution equivalent to randomNonNegativeBigInteger
 * but omitting zero.
 */
static BigInteger randomPositiveBigInteger(int numBits) {
  BigInteger result;
  do {
    result = randomNonNegativeBigInteger(numBits);
  } while (result.signum() == 0);
  return result;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:12,代码来源:MathBenchmarking.java

示例5: format

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Format a BigInteger to produce a string.
 * @param number    The BigInteger to format
 * @param result    where the text is to be appended
 * @param delegate notified of locations of sub fields
 * @return The formatted number string
 * @exception        ArithmeticException if rounding is needed with rounding
 *                   mode being set to RoundingMode.UNNECESSARY
 * @see java.text.FieldPosition
 */
private StringBuffer format(BigInteger number, StringBuffer result,
                           FieldDelegate delegate, boolean formatLong) {
    if (multiplier != 1) {
        number = number.multiply(getBigIntegerMultiplier());
    }
    boolean isNegative = number.signum() == -1;
    if (isNegative) {
        number = number.negate();
    }

    synchronized(digitList) {
        int maxIntDigits, minIntDigits, maxFraDigits, minFraDigits, maximumDigits;
        if (formatLong) {
            maxIntDigits = super.getMaximumIntegerDigits();
            minIntDigits = super.getMinimumIntegerDigits();
            maxFraDigits = super.getMaximumFractionDigits();
            minFraDigits = super.getMinimumFractionDigits();
            maximumDigits = maxIntDigits + maxFraDigits;
        } else {
            maxIntDigits = getMaximumIntegerDigits();
            minIntDigits = getMinimumIntegerDigits();
            maxFraDigits = getMaximumFractionDigits();
            minFraDigits = getMinimumFractionDigits();
            maximumDigits = maxIntDigits + maxFraDigits;
            if (maximumDigits < 0) {
                maximumDigits = Integer.MAX_VALUE;
            }
        }

        digitList.set(isNegative, number,
                      useExponentialNotation ? maximumDigits : 0);

        return subformat(result, delegate, isNegative, true,
            maxIntDigits, minIntDigits, maxFraDigits, minFraDigits);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:47,代码来源:DecimalFormat.java

示例6: generateX

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Generate the private key component of the key pair using the
 * provided source of random bits. This method uses the random but
 * source passed to generate a seed and then calls the seed-based
 * generateX method.
 */
private BigInteger generateX(SecureRandom random, BigInteger q) {
    BigInteger x = null;
    byte[] temp = new byte[qlen];
    while (true) {
        random.nextBytes(temp);
        x = new BigInteger(1, temp).mod(q);
        if (x.signum() > 0 && (x.compareTo(q) < 0)) {
            return x;
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:DSAKeyPairGenerator.java

示例7: testIsPowerOfTwo

import java.math.BigInteger; //导入方法依赖的package包/类
@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));
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:10,代码来源:IntMathTest.java

示例8: toUnsigned

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Return the unsigned value of a BigInteger.
 **/
protected BigInteger toUnsigned (BigInteger b)
{
  if (b != null && b.signum () == -1)
    if (type ().equals ("short"))
      return b.add (twoPow16);
    else if (type ().equals ("long"))
      return b.add (twoPow32);
    else if (type ().equals ("long long"))
      return b.add (twoPow64);
  return b;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:Expression.java

示例9: pair

import java.math.BigInteger; //导入方法依赖的package包/类
static BigInteger pair(BigInteger first, BigInteger second) {
	BigInteger a = first.signum() >= 0 ? TWO.multiply(first) : TWO.negate().multiply(first).subtract(ONE);
	BigInteger b = second.signum() >= 0 ? TWO.multiply(second) : TWO.negate().multiply(second).subtract(ONE);
	if (a.compareTo(b) >= 0) {
		return a.multiply(a).add(a).add(b);
	} else {
		return b.multiply(b).add(a);
	}
}
 
开发者ID:Devskiller,项目名称:friendly-id,代码行数:10,代码来源:ElegantPairing.java

示例10: testNonNegative

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigInteger n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {
        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:DurationImpl.java

示例11: testIsPowerOfTwo

import java.math.BigInteger; //导入方法依赖的package包/类
public void testIsPowerOfTwo() {
  for (BigInteger x : ALL_BIGINTEGER_CANDIDATES) {
    // Checks for a single bit set.
    boolean expected = x.signum() > 0 & x.and(x.subtract(ONE)).equals(ZERO);
    assertEquals(expected, BigIntegerMath.isPowerOfTwo(x));
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:8,代码来源:BigIntegerMathTest.java

示例12: isPowerOfTwo

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Returns {@code true} if {@code x} represents a power of two.
 */
public static boolean isPowerOfTwo(BigInteger x) {
  checkNotNull(x);
  return x.signum() > 0 && x.getLowestSetBit() == x.bitLength() - 1;
}
 
开发者ID:s-store,项目名称:s-store,代码行数:8,代码来源:BigIntegerMath.java

示例13: checkPositive

import java.math.BigInteger; //导入方法依赖的package包/类
static BigInteger checkPositive(@Nullable String role, BigInteger x) {
  if (x.signum() <= 0) {
    throw new IllegalArgumentException(role + " (" + x + ") must be > 0");
  }
  return x;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:7,代码来源:MathPreconditions.java

示例14: enforceSize

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 *  Check an object for type CHAR and VARCHAR and truncate/pad based on
 *  the  size
 *
 * @param  obj   object to check
 * @param  type  the object type
 * @param  size  size to enforce
 * @param check  throw if too long
 * @return       the altered object if the right type, else the object
 *      passed in unaltered
 * @throws HsqlException if data too long
 */
static Object enforceSize(Object obj, int type, int size, int scale,
                          boolean check) throws HsqlException {

    if (obj == null) {
        return obj;
    }

    if (size == 0 && type != Types.TIMESTAMP) {
        return obj;
    }

    // todo: need to handle BINARY like this as well
    switch (type) {

        case Types.CHAR :
            return checkChar((String) obj, size, check);

        case Types.VARCHAR :
        case Types.VARCHAR_IGNORECASE :
            return checkVarchar((String) obj, size, check);

        case Types.NUMERIC :
        case Types.DECIMAL :
            BigDecimal dec = (BigDecimal) obj;

            dec = dec.setScale(scale, BigDecimal.ROUND_HALF_DOWN);

            BigInteger big  = JavaSystem.getUnscaledValue(dec);
            int        sign = big.signum() == -1 ? 1
                                                 : 0;

            if (big.toString().length() - sign > size) {
                throw Trace.error(Trace.STRING_DATA_TRUNCATION);
            }

            return dec;

        case Types.TIMESTAMP :
            if (size == 6) {
                return obj;
            }

            Timestamp ts       = (Timestamp) obj;
            int       nanos    = ts.getNanos();
            int       divisor  = tenPower[size];
            int       newNanos = (nanos / divisor) * divisor;

            ts.setNanos(newNanos);

            return ts;

        default :
            return obj;
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:68,代码来源:Column.java

示例15: bigToDouble

import java.math.BigInteger; //导入方法依赖的package包/类
static double bigToDouble(BigInteger x) {
  // This is an extremely fast implementation of BigInteger.doubleValue(). JDK patch pending.
  BigInteger absX = x.abs();
  int exponent = absX.bitLength() - 1;
  // exponent == floor(log2(abs(x)))
  if (exponent < Long.SIZE - 1) {
    return x.longValue();
  } else if (exponent > MAX_EXPONENT) {
    return x.signum() * POSITIVE_INFINITY;
  }

  /*
   * We need the top SIGNIFICAND_BITS + 1 bits, including the "implicit" one bit. To make rounding
   * easier, we pick out the top SIGNIFICAND_BITS + 2 bits, so we have one to help us round up or
   * down. twiceSignifFloor will contain the top SIGNIFICAND_BITS + 2 bits, and signifFloor the
   * top SIGNIFICAND_BITS + 1.
   *
   * It helps to consider the real number signif = absX * 2^(SIGNIFICAND_BITS - exponent).
   */
  int shift = exponent - SIGNIFICAND_BITS - 1;
  long twiceSignifFloor = absX.shiftRight(shift).longValue();
  long signifFloor = twiceSignifFloor >> 1;
  signifFloor &= SIGNIFICAND_MASK; // remove the implied bit

  /*
   * We round up if either the fractional part of signif is strictly greater than 0.5 (which is
   * true if the 0.5 bit is set and any lower bit is set), or if the fractional part of signif is
   * >= 0.5 and signifFloor is odd (which is true if both the 0.5 bit and the 1 bit are set).
   */
  boolean increment =
      (twiceSignifFloor & 1) != 0 && ((signifFloor & 1) != 0 || absX.getLowestSetBit() < shift);
  long signifRounded = increment ? signifFloor + 1 : signifFloor;
  long bits = (long) ((exponent + EXPONENT_BIAS)) << SIGNIFICAND_BITS;
  bits += signifRounded;
  /*
   * If signifRounded == 2^53, we'd need to set all of the significand bits to zero and add 1 to
   * the exponent. This is exactly the behavior we get from just adding signifRounded to bits
   * directly. If the exponent is MAX_DOUBLE_EXPONENT, we round up (correctly) to
   * Double.POSITIVE_INFINITY.
   */
  bits |= x.signum() & SIGN_MASK;
  return longBitsToDouble(bits);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:44,代码来源:DoubleUtils.java


注:本文中的java.math.BigInteger.signum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。