本文整理汇总了Java中java.math.BigInteger.add方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.add方法的具体用法?Java BigInteger.add怎么用?Java BigInteger.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import java.math.BigInteger; //导入方法依赖的package包/类
private void init(int[] components, int length) {
int pos = 0;
byte[] tmp = new byte[length*5+1]; // +1 for empty input
if (components[1] < Integer.MAX_VALUE - components[0]*40)
pos += pack7Oid(components[0]*40+components[1], tmp, pos);
else {
BigInteger big = BigInteger.valueOf(components[1]);
big = big.add(BigInteger.valueOf(components[0]*40));
pos += pack7Oid(big, tmp, pos);
}
for (int i=2; i<length; i++) {
pos += pack7Oid(components[i], tmp, pos);
}
encoding = new byte[pos];
System.arraycopy(tmp, 0, encoding, 0, pos);
}
示例2: testIsLongTooGreatValue
import java.math.BigInteger; //导入方法依赖的package包/类
@Test
public void testIsLongTooGreatValue() throws Exception {
ParameterDefinition paramDef = initLongParamDef();
VOParameterDefinition voParamDef = ParameterDefinitionAssembler
.toVOParameterDefinition(paramDef, facade);
VOParameter param = new VOParameter(voParamDef);
BigInteger bigInt = BigInteger.valueOf(Long.MAX_VALUE);
BigInteger addValue = BigInteger.valueOf(1);
bigInt = bigInt.add(addValue);
param.setValue(String.valueOf(bigInt));
try {
ParameterAssembler.validateParameter(param, paramDef);
Assert.fail("Operation must fail, as the passed value is not a valid integer");
} catch (ValidationException e) {
Assert.assertEquals("Wrong message key",
"ex.ValidationException.LONG", e.getMessageKey());
Assert.assertEquals("Wrong param number", 1,
e.getMessageParams().length);
Assert.assertEquals("Wrong params", "9223372036854775808",
e.getMessageParams()[0]);
}
}
示例3: write
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
try (
Writer writer = new BufferedWriter(new OutputStreamWriter(output));
JsonGenerator jsonGenerator = new JsonFactory(new ObjectMapper()).createGenerator(writer)
) {
BigInteger index = BigInteger.ONE;
jsonGenerator.writeStartArray();
for (BigInteger v : (Iterable<BigInteger>) bigIntegerStream::iterator) {
try {
jsonGenerator.writeObject(new Sequence(index, v));
index = index.add(BigInteger.ONE);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
jsonGenerator.writeEndArray();
} catch (UncheckedIOException ignored) {}
}
示例4: checkSessionId
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Ensures the session id is an unsigned 64 bit integer
* @param sessionId - session id received from the DPN
* @return unsigned session id
*/
private BigInteger checkSessionId(BigInteger sessionId){
if(sessionId.compareTo(BigInteger.ZERO) < 0){
sessionId = sessionId.add(BigInteger.ONE.shiftLeft(64));
}
return sessionId;
}
示例5: intOp
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger intOp() {
BigInteger val0 = args.get(0).valInt();
BigInteger val1 = args.get(1).valInt();
if (this.nullValue = (args.get(0).isNull() || args.get(1).isNull()))
return BigInteger.ZERO;
return val0.add(val1);
}
示例6: sqrt
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Returns the square root of {@code x}, rounded with the specified rounding mode.
*
* @throws IllegalArgumentException if {@code x < 0}
* @throws ArithmeticException if {@code mode} is {@link RoundingMode#UNNECESSARY} and
* {@code sqrt(x)} is not an integer
*/
@GwtIncompatible("TODO")
@SuppressWarnings("fallthrough")
public static BigInteger sqrt(BigInteger x, RoundingMode mode) {
checkNonNegative("x", x);
if (fitsInLong(x)) {
return BigInteger.valueOf(LongMath.sqrt(x.longValue(), mode));
}
BigInteger sqrtFloor = sqrtFloor(x);
switch (mode) {
case UNNECESSARY:
checkRoundingUnnecessary(sqrtFloor.pow(2).equals(x)); // fall through
case FLOOR:
case DOWN:
return sqrtFloor;
case CEILING:
case UP:
int sqrtFloorInt = sqrtFloor.intValue();
boolean sqrtFloorIsExact =
(sqrtFloorInt * sqrtFloorInt == x.intValue()) // fast check mod 2^32
&& sqrtFloor.pow(2).equals(x); // slow exact check
return sqrtFloorIsExact ? sqrtFloor : sqrtFloor.add(BigInteger.ONE);
case HALF_DOWN:
case HALF_UP:
case HALF_EVEN:
BigInteger halfSquare = sqrtFloor.pow(2).add(sqrtFloor);
/*
* We wish to test whether or not x <= (sqrtFloor + 0.5)^2 = halfSquare + 0.25. Since both
* x and halfSquare are integers, this is equivalent to testing whether or not x <=
* halfSquare.
*/
return (halfSquare.compareTo(x) >= 0) ? sqrtFloor : sqrtFloor.add(BigInteger.ONE);
default:
throw new AssertionError();
}
}
示例7: decodeBase900toBase10
import java.math.BigInteger; //导入方法依赖的package包/类
private static String decodeBase900toBase10(int[] codewords, int count) throws FormatException {
BigInteger result = BigInteger.ZERO;
for (int i = 0; i < count; i++) {
result = result.add(EXP900[(count - i) - 1].multiply(BigInteger.valueOf((long) codewords[i])));
}
String resultString = result.toString();
if (resultString.charAt(0) == '1') {
return resultString.substring(1);
}
throw FormatException.getFormatInstance();
}
示例8: add
import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger add( BigInteger[] a ) {
if ( a.length == 0 )
throw new IllegalArgumentException();
if ( a.length == 1 )
return a[ 0 ];
BigInteger b = a[ 0 ];
for ( int i = 1; i < a.length; i++ )
b = b.add( a[ i ] );
return b;
}
示例9: os2i
import java.math.BigInteger; //导入方法依赖的package包/类
/** Convierte un Octet String de ASN.1 en un entero
* (según <i>BSI TR 03111</i> Sección 3.1.2).
* @param Octet String de ASN.1.
* @param offset posición de inicio-
* @param length longitud del Octet String.
* @return Entero (siempre positivo). */
private static BigInteger os2i(final byte[] bytes, final int offset, final int length) {
if (bytes == null) {
throw new IllegalArgumentException("El Octet String no puede ser nulo"); //$NON-NLS-1$
}
BigInteger result = BigInteger.ZERO;
final BigInteger base = BigInteger.valueOf(256);
for (int i = offset; i < offset + length; i++) {
result = result.multiply(base);
result = result.add(BigInteger.valueOf(bytes[i] & 0xFF));
}
return result;
}
示例10: createIdentificationGroup
import java.math.BigInteger; //导入方法依赖的package包/类
private IdentificationGroup createIdentificationGroup(BigInteger p_hat, SecurityParameters securityParameters) {
log.info("creating identification group");
IdentificationGroup identificationGroup = null;
while (identificationGroup == null) {
BigInteger p_hatMinusOne = p_hat.subtract(ONE);
BigInteger k = TWO;
while (p_hatMinusOne.mod(k).compareTo(ZERO) != 0) {
k = k.add(ONE);
}
BigInteger q_hat = p_hatMinusOne.divide(k);
if (!q_hat.isProbablePrime(100)) {
log.info("q_hat is not prime");
continue;
}
if (q_hat.bitLength() < 2 * securityParameters.getTau()) {
log.info("|q_hat| < 2*mu");
continue;
}
BigInteger i = randomGenerator.randomInZq(p_hat);
while (modExp(i, k, p_hat).compareTo(ONE) == 0) {
i = randomGenerator.randomInZq(p_hat);
}
BigInteger g_hat = modExp(i, k, p_hat);
try {
identificationGroup = new IdentificationGroup(p_hat, q_hat, g_hat);
} catch (IllegalArgumentException e) {
log.warn("failed to create identification group", e);
identificationGroup = null;
}
}
log.info("created identification group");
return identificationGroup;
}
示例11: valueOf
import java.math.BigInteger; //导入方法依赖的package包/类
public BigInteger valueOf(long i0, long i1, long i2, long i3) {
BigInteger low = valueOf(i0, i1);
if (i2 == 0 && i3 == 0) {
return low;
}
BigInteger high = valueOf(i2, i3);
return low.add(high.shiftLeft(128));
}
示例12: sqrt
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Returns the square root of {@code x}, rounded with the specified rounding mode.
*
* @throws IllegalArgumentException if {@code x < 0}
* @throws ArithmeticException if {@code mode} is {@link RoundingMode#UNNECESSARY} and
* {@code sqrt(x)} is not an integer
*/
@GwtIncompatible // TODO
@SuppressWarnings("fallthrough")
public static BigInteger sqrt(BigInteger x, RoundingMode mode) {
checkNonNegative("x", x);
if (fitsInLong(x)) {
return BigInteger.valueOf(LongMath.sqrt(x.longValue(), mode));
}
BigInteger sqrtFloor = sqrtFloor(x);
switch (mode) {
case UNNECESSARY:
checkRoundingUnnecessary(sqrtFloor.pow(2).equals(x)); // fall through
case FLOOR:
case DOWN:
return sqrtFloor;
case CEILING:
case UP:
int sqrtFloorInt = sqrtFloor.intValue();
boolean sqrtFloorIsExact =
(sqrtFloorInt * sqrtFloorInt == x.intValue()) // fast check mod 2^32
&& sqrtFloor.pow(2).equals(x); // slow exact check
return sqrtFloorIsExact ? sqrtFloor : sqrtFloor.add(BigInteger.ONE);
case HALF_DOWN:
case HALF_UP:
case HALF_EVEN:
BigInteger halfSquare = sqrtFloor.pow(2).add(sqrtFloor);
/*
* We wish to test whether or not x <= (sqrtFloor + 0.5)^2 = halfSquare + 0.25. Since both x
* and halfSquare are integers, this is equivalent to testing whether or not x <=
* halfSquare.
*/
return (halfSquare.compareTo(x) >= 0) ? sqrtFloor : sqrtFloor.add(BigInteger.ONE);
default:
throw new AssertionError();
}
}
示例13: next
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger next(BigInteger value) {
return value.add(BigInteger.ONE);
}
示例14: isIn20PercentRange
import java.math.BigInteger; //导入方法依赖的package包/类
public static boolean isIn20PercentRange(BigInteger first, BigInteger second) {
BigInteger five = BigInteger.valueOf(5);
BigInteger limit = first.add(first.divide(five));
return !isMoreThan(second, limit);
}
示例15: det
import java.math.BigInteger; //导入方法依赖的package包/类
/** Determinant of an integer square matrix.
* @param A The square matrix.
* If column and row dimensions are unequal, an ArithmeticException is thrown.
* @return The determinant.
* @since 2010-08-27
* @author Richard J. Mathar
*/
static public BigInteger det(final BigInteger[][] A) throws ArithmeticException
{
BigInteger d = BigInteger.ZERO ;
/* row size */
final int rL = A.length ;
if ( rL == 0 )
throw new ArithmeticException("zero row count in matrix") ;
/* column size */
final int cL = A[0].length ;
if ( cL != rL )
throw new ArithmeticException("Non-square matrix dim "+rL + " by " + cL) ;
/* Compute the low-order cases directly.
*/
if ( rL == 1 )
return A[0][0] ;
else if ( rL == 2)
{
d = A[0][0].multiply(A[1][1]) ;
return d.subtract( A[0][1].multiply(A[1][0])) ;
}
else
{
/* Work arbitrarily along the first column of the matrix */
for (int r = 0 ; r < rL ; r++)
{
/* Do not consider minors that do no contribute anyway
*/
if ( A[r][0].compareTo(BigInteger.ZERO) != 0 )
{
final BigInteger M[][] = minor(A,r,0) ;
final BigInteger m = A[r][0].multiply( det(M)) ;
/* recursive call */
if ( r % 2 == 0)
d = d.add(m) ;
else
d = d.subtract(m) ;
}
}
}
return d;
}