List of utility methods to do BigInteger Calculate
BigInteger[] | splitFloat(BigInteger rawFloat, int signWidth, int exponentWidth, int mantissaWidth) split Float BigInteger rawSign = rawFloat.shiftRight(exponentWidth + mantissaWidth) .and(BigInteger.ONE.shiftLeft(signWidth).subtract(BigInteger.ONE)); BigInteger rawExponent = rawFloat.shiftRight(mantissaWidth) .and(BigInteger.ONE.shiftLeft(exponentWidth).subtract(BigInteger.ONE)); BigInteger rawMantissa = rawFloat.and(BigInteger.ONE.shiftLeft(mantissaWidth).subtract(BigInteger.ONE)); return new BigInteger[] { rawSign, rawExponent, rawMantissa }; |
BigInteger | sqrt(BigInteger n) Computes the integer square root of a number. if (n.signum() >= 0) { final int bitLength = n.bitLength(); BigInteger root = BigInteger.ONE.shiftLeft(bitLength / 2); while (!isSqrtXXX(n, root)) root = root.add(n.divide(root)).divide(TWO); return root; } else throw new ArithmeticException("square root of negative number"); ... |
BigInteger | sqrt(BigInteger n) sqrt BigInteger a = BigInteger.ONE; BigInteger b = new BigInteger(n.shiftRight(5).add(new BigInteger("8")).toString()); while (b.compareTo(a) >= 0) { BigInteger mid = new BigInteger(a.add(b).shiftRight(1).toString()); if (mid.multiply(mid).compareTo(n) > 0) b = mid.subtract(BigInteger.ONE); else a = mid.add(BigInteger.ONE); ... |
BigInteger | sqrt(BigInteger n) Computes the square root of a BigInteger BigInteger a = BigInteger.ONE; BigInteger b = n.shiftRight(5).add(EIGHT); while (b.compareTo(a) >= 0) { BigInteger mid = a.add(b).shiftRight(1); if (mid.multiply(mid).compareTo(n) > 0) b = mid.subtract(BigInteger.ONE); else a = mid.add(BigInteger.ONE); ... |
BigInteger | square(BigInteger x) square final int bitLength = x.bitLength(); if (bitLength < 1800) { return x.multiply(x); if (x.signum() < 0) { x = x.negate(); final int n = addInts(bitLength, 1) / 2; ... |
BigInteger[] | subArray(BigInteger[] input, int start, int end) Generates a subarray of a given BigInteger array. BigInteger[] result = new BigInteger[end - start]; System.arraycopy(input, start, result, 0, end - start); return result; |
String | substring(final String lhs, final BigInteger _start, final BigInteger _end) substring int start = _start.intValue(); int end = _end.intValue(); return lhs.substring(start, end); |
BigInteger | sum(BigInteger valueA, BigInteger valueB) sum return valueA.add(valueB);
|
BigInteger | sum(BigInteger... values) Sums an array of BigIntegers, ignoring null values. int count = 0; BigInteger total = BigInteger.ZERO; for (BigInteger value : values) { if (value == null) { continue; count++; total = total.add(value); ... |
long | sumOfDigits(BigInteger ab) sum Of Digits String number = ab.toString();
return sumOfDigits(number);
|