本文整理匯總了Java中com.google.common.math.LongMath.sqrt方法的典型用法代碼示例。如果您正苦於以下問題:Java LongMath.sqrt方法的具體用法?Java LongMath.sqrt怎麽用?Java LongMath.sqrt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.math.LongMath
的用法示例。
在下文中一共展示了LongMath.sqrt方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sqrt
import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Benchmark int sqrt(int reps) {
int tmp = 0;
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
tmp += LongMath.sqrt(positive[j], mode);
}
return tmp;
}
示例2: sqrt
import com.google.common.math.LongMath; //導入方法依賴的package包/類
/**
* 開方
*/
public static long sqrt(long x, RoundingMode mode) {
return LongMath.sqrt(x, mode);
}
示例3: countRoot1021
import com.google.common.math.LongMath; //導入方法依賴的package包/類
/**
* Determine the n-th root from the prime decomposition of the primes[] array.
*
* @param val
* a BigInteger value which should be factored by all primes less equal than 1021
* @param root
* th n-th root which should be determined
* @return <code>(result[0] ^ root ) * result[1]</code>
*/
public static long[] countRoot1021(final long val, int root) {
long[] result = new long[2];
result[1] = val;
result[0] = 1L;
long sqrt = LongMath.sqrt(val, RoundingMode.DOWN);
long count = 0;
long temp = val;
// handle even values
while ((temp & 0x00000001) == 0x00000000 && temp != 0L) {
temp = temp >> 1L;
count++;
if (count == root) {
count = 0;
result[1] = result[1] >> root;
result[0] = result[0] << 1L;
}
}
for (int i = 1; i < primes.length; i++) {
if (sqrt < primes[i]) {
break;
}
count = 0;
// divRem = temp.divideAndRemainder(BIprimes[i]);
long[] divRem = new long[2];
divRem[0] = temp / primes[i];
divRem[1] = temp % primes[i];
while (divRem[1] == 0L) {
count++;
if (count == root) {
count = 0;
// result[1] = result[1] / (primes[i].pow(root));
result[1] = result[1] / pow(primes[i], root);
result[0] = result[0] * primes[i];
}
temp = divRem[0];// quotient
if (temp < primes[i]) {
break;
}
// divRem = temp.divideAndRemainder(BIprimes[i]);
divRem[0] = temp / primes[i];
divRem[1] = temp % primes[i];
}
}
return result;
}