List of usage examples for java.math BigInteger ONE
BigInteger ONE
To view the source code for java.math BigInteger ONE.
Click Source Link
From source file:cc.redberry.core.number.Exponentiation.java
static BigInteger findIntegerRoot(BigInteger base, BigInteger power) { BigInteger maxBits = BigInteger.valueOf(base.bitLength() + 1); // base < 2 ^ (maxBits + 1) // => base ^ ( 1 / power ) < 2 ^ ( (maxBits + 1) / power ) BigInteger[] divResult = maxBits.divideAndRemainder(power); if (divResult[1].signum() == 0) // i.e. divResult[1] == 0 maxBits = divResult[0];/*from www . j a v a 2s. c o m*/ else maxBits = divResult[0].add(BigInteger.ONE); if (maxBits.bitLength() > 31) throw new RuntimeException("Too many bits..."); int targetBitsNumber = maxBits.intValue(); int resultLengthM1 = targetBitsNumber / 8 + 1; //resultLength minus one byte[] result = new byte[resultLengthM1]; resultLengthM1--; int bitNumber = targetBitsNumber; int cValue; BigInteger testValue; while ((--bitNumber) >= 0) { //setting bit result[resultLengthM1 - (bitNumber >> 3)] |= 1 << (bitNumber & 0x7); //Testing testValue = new BigInteger(result); cValue = ArithmeticUtils.pow(testValue, power).compareTo(base); if (cValue == 0) return testValue; if (cValue > 0) result[resultLengthM1 - (bitNumber >> 3)] &= ~(1 << (bitNumber & 0x7)); } return null; }
From source file:cherry.foundation.type.SecureBigIntegerTest.java
@Test public void testNoneEncoder() { Encoder<BigInteger> encoder = new SecureBigInteger.NoneEncoder(); assertThat(encoder.encode(null), is(nullValue())); assertThat(encoder.encode(BigInteger.ONE), is("1")); assertThat(encoder.decode(null), is(nullValue())); assertThat(encoder.decode("1"), is(BigInteger.ONE)); }
From source file:RSA.java
/** Generate a new public and private key set. */ public synchronized void generateKeys() { SecureRandom r = new SecureRandom(); BigInteger p = new BigInteger(bitlen / 2, 100, r); BigInteger q = new BigInteger(bitlen / 2, 100, r); n = p.multiply(q);//from w w w .jav a2s . c o m BigInteger m = (p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE)); e = new BigInteger("3"); while (m.gcd(e).intValue() > 1) { e = e.add(new BigInteger("2")); } d = e.modInverse(m); }
From source file:org.apache.accumulo.server.master.tableOps.Utils.java
static String getNextTableId(String tableName, Instance instance) throws ThriftTableOperationException { String tableId = null;//from www . j a v a 2s. c o m try { IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance(); final String ntp = ZooUtil.getRoot(instance) + Constants.ZTABLES; byte[] nid = zoo.mutate(ntp, "0".getBytes(), ZooUtil.PUBLIC, new Mutator() { @Override public byte[] mutate(byte[] currentValue) throws Exception { BigInteger nextId = new BigInteger(new String(currentValue), Character.MAX_RADIX); nextId = nextId.add(BigInteger.ONE); return nextId.toString(Character.MAX_RADIX).getBytes(); } }); return new String(nid); } catch (Exception e1) { Logger.getLogger(CreateTable.class).error("Failed to assign tableId to " + tableName, e1); throw new ThriftTableOperationException(tableId, tableName, TableOperation.CREATE, TableOperationExceptionType.OTHER, e1.getMessage()); } }
From source file:co.rsk.remasc.RemascStorageProviderTest.java
@Test public void setAndGetRewardBalance() { String accountAddress = randomAddress(); Repository repository = new RepositoryImpl(); RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress); provider.setRewardBalance(BigInteger.ONE); Assert.assertEquals(BigInteger.ONE, provider.getRewardBalance()); }
From source file:org.eclipse.equinox.p2.cudf.solver.TrendyOptimizationFunction.java
public List<WeightedObject<Object>> createOptimizationFunction(InstallableUnit metaIu) { List<WeightedObject<Object>> weightedObjects = new ArrayList<WeightedObject<Object>>(); BigInteger weight = BigInteger.valueOf(slice.size() + 1); removed(weightedObjects, weight.multiply(weight).multiply(weight), metaIu); notuptodate(weightedObjects, weight.multiply(weight), metaIu); optional(weightedObjects, weight, metaIu); niou(weightedObjects, BigInteger.ONE, metaIu); if (!weightedObjects.isEmpty()) { return weightedObjects; }/*from w w w. jav a2 s . c om*/ return null; }
From source file:org.spring.cache.CachingWithGeodeIntegrationTest.java
@Test public void aCacheMisses() { assertThat(mathService.factorial(BigInteger.valueOf(0)), is(equalTo(BigInteger.ONE))); assertThat(mathService.wasCacheMiss(), is(true)); assertThat(mathService.factorial(BigInteger.valueOf(1)), is(equalTo(BigInteger.ONE))); assertThat(mathService.wasCacheMiss(), is(true)); assertThat(mathService.factorial(BigInteger.valueOf(2)), is(equalTo(MathService.TWO))); assertThat(mathService.wasCacheMiss(), is(true)); assertThat(mathService.factorial(BigInteger.valueOf(4)), is(equalTo(BigInteger.valueOf(24)))); assertThat(mathService.wasCacheMiss(), is(true)); assertThat(mathService.factorial(BigInteger.valueOf(8)), is(equalTo(BigInteger.valueOf(40320)))); assertThat(mathService.wasCacheMiss(), is(true)); }
From source file:cc.redberry.core.number.NumberUtils.java
private static boolean isSqrtXXX(BigInteger n, BigInteger root) { final BigInteger lowerBound = root.pow(2); final BigInteger upperBound = root.add(BigInteger.ONE).pow(2); return lowerBound.compareTo(n) <= 0 && n.compareTo(upperBound) < 0; }
From source file:Mersenne.java
public Mersenne(int index) { this.index = index; value = two.pow(Integer.parseInt(primes[index - 1])); value = value.subtract(BigInteger.ONE); }
From source file:org.apache.accumulo.master.tableOps.Utils.java
static String getNextTableId(String tableName, Instance instance) throws ThriftTableOperationException { String tableId = null;// w ww.j a v a2s. c o m try { IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance(); final String ntp = ZooUtil.getRoot(instance) + Constants.ZTABLES; byte[] nid = zoo.mutate(ntp, ZERO_BYTE, ZooUtil.PUBLIC, new Mutator() { @Override public byte[] mutate(byte[] currentValue) throws Exception { BigInteger nextId = new BigInteger(new String(currentValue, Constants.UTF8), Character.MAX_RADIX); nextId = nextId.add(BigInteger.ONE); return nextId.toString(Character.MAX_RADIX).getBytes(Constants.UTF8); } }); return new String(nid, Constants.UTF8); } catch (Exception e1) { Logger.getLogger(CreateTable.class).error("Failed to assign tableId to " + tableName, e1); throw new ThriftTableOperationException(tableId, tableName, TableOperation.CREATE, TableOperationExceptionType.OTHER, e1.getMessage()); } }