本文整理匯總了Java中com.google.common.math.LongMath.pow方法的典型用法代碼示例。如果您正苦於以下問題:Java LongMath.pow方法的具體用法?Java LongMath.pow怎麽用?Java LongMath.pow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.math.LongMath
的用法示例。
在下文中一共展示了LongMath.pow方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: bitsForNumElementsWithLoadFactor
import com.google.common.math.LongMath; //導入方法依賴的package包/類
static int bitsForNumElementsWithLoadFactor(long numElements) {
if (numElements == 0) {
return 1;
}
int candidateBits = Long.bitCount(numElements) == 1 ?
Math.max(1, Long.numberOfTrailingZeros(numElements)) :
Long.numberOfTrailingZeros(Long.highestOneBit(numElements) << 1L);
//May need an extra bit due to load factor
if (((long) (LongMath.pow(2, candidateBits) * 0.75)) < numElements) {
candidateBits++;
}
return candidateBits;
}
示例2: IdGenerator
import com.google.common.math.LongMath; //導入方法依賴的package包/類
/**
* @param alphabet the alphabet of legal characters for IDs generated by this generator
* @param perturb whether or not to perturb generated IDs by a random perturbation to avoid
* collisions in distributed key generation. Pass {@code false} if this generator
* is used to generate a sort key that is a secondary key where ordering
* conflicts can be deterministically resolved by the primary key. This setting
* only applies to the {@code generate...} methods.
*/
public IdGenerator(IdAlphabet alphabet, boolean perturb) {
mAlphabet = alphabet;
mPerturb = perturb;
// Find the maximum number of digits we'd need to encode an unsigned long if the radix were
// uniform for the entire string.
// ceil(log_RADIX(Long.MAX + 1))
mLongUniformRadixLength = (int) Math.ceil(LOG_LONG / Math.log(alphabet.radix()));
mMostSignificantUnit = LongMath.pow(alphabet.radix(), mLongUniformRadixLength - 1);
mMaxSafeMostSignificantDigit = (int) (Long.MAX_VALUE / mMostSignificantUnit);
mMaxSafeMostSignificantValue = mMaxSafeMostSignificantDigit * mMostSignificantUnit;
// The first character may have additional restrictions, so we have less chars to work with
// for the first digit. If we still have enough digits, we'll proceed and just use a special
// mapping for the leading digit. Otherwise, we'll pad by a leading zero, thus making the
// remaining encoding the common case.
// So, what most-significant digit do we need to encode the max unsigned value?
PartialDivisionResult div = transformToSignedDivision(-1);
int maxMostSignficantDigit = div.partialMostSignificantDigit +
(int) (div.partialRemainder / mMostSignificantUnit);
mLongEncodedLength = maxMostSignficantDigit < alphabet.leadingRadix() ?
mLongUniformRadixLength : mLongUniformRadixLength + 1;
}
示例3: toL
import com.google.common.math.LongMath; //導入方法依賴的package包/類
private static Long toL(String value) {
if (null == value) {
return 0L;
}
int idxSep = value.indexOf(SEPARATOR_CHAR);
if (idxSep > -1) {
value = value.substring(idxSep + 1);
}
long r = 0;
int length = value.length();
for (int i = 0; i < length; i++) {
long val = LongMath.pow(RADIX, (length - i - 1));
char c = value.charAt(i);
int tmp = KEYS.indexOf(c);
r += (tmp * val);
}
return r;
}
示例4: getBytes
import com.google.common.math.LongMath; //導入方法依賴的package包/類
protected static byte[] getBytes(long sum, int arraySize) {
final byte[] b = new byte[arraySize];
for (int i = 0; i < b.length; i++) {
final int reverseIndex = b.length - 1 - i;
final long factor = LongMath.pow(256, reverseIndex);
final long base = sum / factor;
b[i] = UnsignedBytes.checkedCast(base);
sum = sum - (base * factor);
}
return b;
}
示例5: getLong
import com.google.common.math.LongMath; //導入方法依賴的package包/類
protected static long getLong(byte[] b) {
long sum = 0;
for (int i = 0; i < b.length; i++) {
final int reverseIndex = b.length - 1 - i;
final long factor = LongMath.pow(256, reverseIndex);
final int base = UnsignedBytes.toInt(b[i]);
sum += base * factor;
}
return sum;
}
示例6: pow
import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Benchmark int pow(int reps) {
int tmp = 0;
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
tmp += LongMath.pow(positive[j], exponents[j]);
}
return tmp;
}
示例7: buildChartAndTableEntries
import com.google.common.math.LongMath; //導入方法依賴的package包/類
private void buildChartAndTableEntries(List<Offer> sortedList, OfferPayload.Direction direction, List<XYChart.Data> data, ObservableList<OfferListItem> offerTableList) {
data.clear();
double accumulatedAmount = 0;
List<OfferListItem> offerTableListTemp = new ArrayList<>();
for (Offer offer : sortedList) {
Price price = offer.getPrice();
if (price != null) {
double amount = (double) offer.getAmount().value / LongMath.pow(10, offer.getAmount().smallestUnitExponent());
accumulatedAmount += amount;
offerTableListTemp.add(new OfferListItem(offer, accumulatedAmount));
double priceAsDouble = (double) price.getValue() / LongMath.pow(10, price.smallestUnitExponent());
if (CurrencyUtil.isCryptoCurrency(getCurrencyCode())) {
if (direction.equals(OfferPayload.Direction.SELL))
data.add(0, new XYChart.Data<>(priceAsDouble, accumulatedAmount));
else
data.add(new XYChart.Data<>(priceAsDouble, accumulatedAmount));
} else {
if (direction.equals(OfferPayload.Direction.BUY))
data.add(0, new XYChart.Data<>(priceAsDouble, accumulatedAmount));
else
data.add(new XYChart.Data<>(priceAsDouble, accumulatedAmount));
}
}
}
offerTableList.setAll(offerTableListTemp);
}
示例8: pur
import com.google.common.math.LongMath; //導入方法依賴的package包/類
private static long pur(int p) {
return LongMath.pow(2, p); //(long) Math.pow(2, p) 2^p
}
示例9: calcIncLength
import com.google.common.math.LongMath; //導入方法依賴的package包/類
private void calcIncLength(int len) {
this.increaseLengthAt = LongMath.pow(numberSystem.getDigits()
.length(), len);
}
示例10: getMaximalAffinityMask
import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Override
public long getMaximalAffinityMask() {
return LongMath.pow(2, Runtime.getRuntime().availableProcessors())-1;
}
示例11: pow
import com.google.common.math.LongMath; //導入方法依賴的package包/類
/**
* 平方
*
* @param k
* 平方次數,不能為負數, k=0時返回1.
*/
public static long pow(long b, int k) {
return LongMath.pow(b, k);
}