List of usage examples for java.math BigInteger divide
public BigInteger divide(BigInteger val)
From source file:jp.co.acroquest.endosnipe.report.converter.util.calc.BigIntegerCalculator.java
public Object div(Object obj1, Object obj2) { BigInteger integerData1 = (BigInteger) obj1; BigInteger integerData2 = (BigInteger) obj2; return (Object) (integerData1.divide(integerData2)); }
From source file:burstcoin.jminer.core.checker.task.OCLCheckerFindAllBelowTargetTask.java
@Override public void run() { int[] lowestNonces; synchronized (oclChecker) { // todo not working?! lowestNonces = oclChecker.findTarget(generationSignature, scoops, targetDeadline); }//from w w w . j av a2s . c om if (lowestNonces != null) { List<DevPoolResult> devPoolResults = new ArrayList<>(); for (int lowestNonce : lowestNonces) { long nonce = chunkPartStartNonce + lowestNonce; BigInteger result = calculateResult(scoops, generationSignature, lowestNonce); BigInteger deadline = result.divide(BigInteger.valueOf(baseTarget)); long calculatedDeadline = deadline.longValue(); devPoolResults.add(new DevPoolResult(blockNumber, calculatedDeadline, nonce, chunkPartStartNonce)); } publisher.publishEvent(new CheckerDevResultEvent(blockNumber, chunkPartStartNonce, devPoolResults)); } else { publisher.publishEvent(new CheckerDevResultEvent(blockNumber, chunkPartStartNonce, null)); } }
From source file:org.gridobservatory.greencomputing.adapters.Machine.java
public void setDateCreated(BigInteger value) { this.machineType.setDateCreated(value.divide(BigInteger.valueOf(1000L))); }
From source file:org.stem.domain.TokenBalancer.java
public T getToken(byte[] keyBytes) { BigInteger token = new BigInteger(new String(Hex.encodeHex(keyBytes)), 16); BigInteger delta = MD5_MAX_VALUE.divide(BigInteger.valueOf(keySet.size())); int keyIndex = Math.max(token.divide(delta).intValue() - 1, 0); if (keyIndex >= keySet.size()) { throw new RuntimeException("Token " + keyBytes + " is out of range"); }/* w w w . j a v a2 s.c om*/ return keySet.get(keyIndex); }
From source file:org.stem.domain.DHT.java
public int getSection(byte[] keyBytes) { BigInteger token = new BigInteger(new String(Hex.encodeHex(keyBytes)), 16); BigInteger sectionSize = capacity.divide(BigInteger.valueOf(sections)); int quotient = token.divide(sectionSize).intValue(); BigInteger mod = token.mod(sectionSize); int index;/*w w w.j a v a 2 s . c o m*/ if (quotient == 0) index = 0; else if (mod.equals(BigInteger.ZERO)) index = Math.max(quotient - 1, 0); else index = Math.max(quotient, 0); if (index >= sections) { return sections - 1; } return index; }
From source file:PalidromeArray.java
public PalidromeArray(BigInteger totalLength) { this.totalLength = totalLength; this.halfLength = totalLength.divide(TWO); if (MathUtil.isOdd(totalLength)) { isEven = false;/*from w ww.java 2s . c o m*/ halfLength = halfLength.add(BigInteger.ONE); } array = new ConcurrentHashMap<BigInteger, BigInteger>(); }
From source file:org.trnltk.numeral.DigitsToTextConverter.java
private int getNthGroupNumber(BigInteger naturalNumber, int n) { naturalNumber = naturalNumber.divide(ONE_THOUSAND.pow(n)); naturalNumber = naturalNumber.mod(ONE_THOUSAND); return naturalNumber.intValue(); }
From source file:com.github.fge.jsonschema.format.draftv3.UTCMillisecAttribute.java
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); BigInteger epoch = instance.bigIntegerValue(); if (epoch.signum() == -1) { report.warn(newMsg(data, bundle, "warn.format.epoch.negative").putArgument("value", instance)); return;//from w w w . jav a 2 s. c om } epoch = epoch.divide(ONE_THOUSAND); if (epoch.bitLength() > EPOCH_BITLENGTH) report.warn(newMsg(data, bundle, "warn.format.epoch.overflow").putArgument("value", instance)); }
From source file:libra.preprocess.common.kmerhistogram.KmerRangePartitioner.java
public KmerRangePartition[] getEqualRangePartitions() { KmerRangePartition[] partitions = new KmerRangePartition[this.numPartitions]; // calc 4^kmerSize BigInteger kmerend = BigInteger.valueOf(4).pow(this.kmerSize); BigInteger slice_width = kmerend.divide(BigInteger.valueOf(this.numPartitions)); if (kmerend.mod(BigInteger.valueOf(this.numPartitions)).intValue() != 0) { slice_width = slice_width.add(BigInteger.ONE); }//from w w w . j ava2 s.c o m for (int i = 0; i < this.numPartitions; i++) { BigInteger slice_begin = slice_width.multiply(BigInteger.valueOf(i)); if (slice_begin.add(slice_width).compareTo(kmerend) > 0) { slice_width = kmerend.subtract(slice_begin); } BigInteger slice_end = slice_begin.add(slice_width).subtract(BigInteger.ONE); KmerRangePartition slice = new KmerRangePartition(this.kmerSize, this.numPartitions, i, slice_width, slice_begin, slice_end); partitions[i] = slice; } return partitions; }
From source file:org.apache.hama.util.Bytes.java
/** * Split passed range. Expensive operation relatively. Uses BigInteger math. * //from w ww. ja v a2 s . co m * @param a Beginning of range * @param b End of range * @param num Number of times to split range. Pass 1 if you want to split the * range in two; i.e. one split. * @return Array of dividing values */ public static byte[][] split(final byte[] a, final byte[] b, final int num) { byte[] aPadded; byte[] bPadded; if (a.length < b.length) { aPadded = padTail(a, b.length - a.length); bPadded = b; } else if (b.length < a.length) { aPadded = a; bPadded = padTail(b, a.length - b.length); } else { aPadded = a; bPadded = b; } if (compareTo(aPadded, bPadded) >= 0) { throw new IllegalArgumentException("b <= a"); } if (num <= 0) { throw new IllegalArgumentException("num cannot be < 0"); } byte[] prependHeader = { 1, 0 }; BigInteger startBI = new BigInteger(add(prependHeader, aPadded)); BigInteger stopBI = new BigInteger(add(prependHeader, bPadded)); BigInteger diffBI = stopBI.subtract(startBI); BigInteger splitsBI = BigInteger.valueOf(num + 1); if (diffBI.compareTo(splitsBI) < 0) { return null; } BigInteger intervalBI; try { intervalBI = diffBI.divide(splitsBI); } catch (Exception e) { LOG.error("Exception caught during division", e); return null; } byte[][] result = new byte[num + 2][]; result[0] = a; for (int i = 1; i <= num; i++) { BigInteger curBI = startBI.add(intervalBI.multiply(BigInteger.valueOf(i))); byte[] padded = curBI.toByteArray(); if (padded[1] == 0) padded = tail(padded, padded.length - 2); else padded = tail(padded, padded.length - 1); result[i] = padded; } result[num + 1] = b; return result; }