BigInteger.
The implementations of many methods in this class are based on material from Henry S. Warren, Jr.'s Hacker's Delight, (Addison Wesley, 2002).
Similar functionality for int and for long can be found in IntMath and
LongMath respectively.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final double | |
| private static final double | |
| pack-priv static final int | |
| pack-priv static final BigInteger |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static BigInteger | binomial(int n, int k)
Returns |
| public static BigInteger | |
| public static BigInteger | divide(BigInteger p, BigInteger q, RoundingMode mode)
Returns the result of dividing |
| public static BigInteger | |
| pack-priv static boolean | |
| public static BigInteger | |
| public static boolean | |
| pack-priv static BigInteger | |
| pack-priv static BigInteger | |
| public static int | log10(BigInteger x, RoundingMode mode)
Returns the base-10 logarithm of |
| public static int | log2(BigInteger x, RoundingMode mode)
Returns the base-2 logarithm of |
| public static double | roundToDouble(BigInteger x, RoundingMode mode)
Returns |
| public static BigInteger | sqrt(BigInteger x, RoundingMode mode)
Returns the square root of |
| private static BigInteger | |
| private static BigInteger |
| LN_10 | back to summary |
|---|---|
| private static final double LN_10 | |
| LN_2 | back to summary |
|---|---|
| private static final double LN_2 | |
| SQRT2_PRECOMPUTE_THRESHOLD | back to summary |
|---|---|
| pack-priv static final int SQRT2_PRECOMPUTE_THRESHOLD
| |
| SQRT2_PRECOMPUTED_BITS | back to summary |
|---|---|
| pack-priv static final BigInteger SQRT2_PRECOMPUTED_BITS
| |
| BigIntegerMath | back to summary |
|---|---|
| private BigIntegerMath() | |
| binomial | back to summary |
|---|---|
| public static BigInteger binomial(int n, int k) Returns Warning the result can take as much as O(k log n) space.
| |
| ceilingPowerOfTwo | back to summary |
|---|---|
| public static BigInteger ceilingPowerOfTwo(BigInteger x) Returns the smallest power of two greater than or equal to
| |
| divide | back to summary |
|---|---|
| public static BigInteger divide(BigInteger p, BigInteger q, RoundingMode mode) Returns the result of dividing
| |
| factorial | back to summary |
|---|---|
| public static BigInteger factorial(int n) Returns Warning the result takes O(n log n) space, so use cautiously. This uses an efficient binary recursive algorithm to compute the factorial with balanced multiplies. It also removes all the 2s from the intermediate products (shifting them back in at the end).
| |
| fitsInLong | back to summary |
|---|---|
pack-priv static boolean fitsInLong(BigInteger x)
| |
| floorPowerOfTwo | back to summary |
|---|---|
| public static BigInteger floorPowerOfTwo(BigInteger x) Returns the largest power of two less than or equal to
| |
| isPowerOfTwo | back to summary |
|---|---|
| public static boolean isPowerOfTwo(BigInteger x) Returns | |
| listProduct | back to summary |
|---|---|
| pack-priv static BigInteger listProduct(List<BigInteger> nums) | |
| listProduct | back to summary |
|---|---|
| pack-priv static BigInteger listProduct(List<BigInteger> nums, int start, int end) | |
| log10 | back to summary |
|---|---|
| public static int log10(BigInteger x, RoundingMode mode) Returns the base-10 logarithm of
| |
| log2 | back to summary |
|---|---|
| public static int log2(BigInteger x, RoundingMode mode) Returns the base-2 logarithm of
| |
| roundToDouble | back to summary |
|---|---|
| public static double roundToDouble(BigInteger x, RoundingMode mode) Returns For the case of For the case of
| |
| sqrt | back to summary |
|---|---|
| public static BigInteger sqrt(BigInteger x, RoundingMode mode) Returns the square root of
| |
| sqrtApproxWithDoubles | back to summary |
|---|---|
private static BigInteger sqrtApproxWithDoubles(BigInteger x)
| |
| sqrtFloor | back to summary |
|---|---|
private static BigInteger sqrtFloor(BigInteger x)
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final BigIntegerMath. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv BigInteger | minus(BigInteger a, BigInteger b)
Implements abstract com. |
| pack-priv double | roundToDoubleArbitrarily(BigInteger bigInteger)
Implements abstract com. |
| pack-priv int | sign(BigInteger bigInteger)
Implements abstract com. |
| pack-priv BigInteger | toX(double d, RoundingMode mode)
Implements abstract com. |
| INSTANCE | back to summary |
|---|---|
| pack-priv static final BigIntegerMath. | |
| BigIntegerToDoubleRounder | back to summary |
|---|---|
| private BigIntegerToDoubleRounder() | |
| minus | back to summary |
|---|---|
| pack-priv BigInteger minus(BigInteger a, BigInteger b) Implements abstract com. Doc from com. Returns a - b, guaranteed that both arguments are nonnegative.
| |
| roundToDoubleArbitrarily | back to summary |
|---|---|
| pack-priv double roundToDoubleArbitrarily(BigInteger bigInteger) Implements abstract com. Doc from com. Returns x rounded to either the greatest double less than or equal to the precise value of x, or the least double greater than or equal to the precise value of x.
| |
| sign | back to summary |
|---|---|
| pack-priv int sign(BigInteger bigInteger) Implements abstract com. Doc from com. Returns the sign of x: either -1, 0, or 1.
| |
| toX | back to summary |
|---|---|
| pack-priv BigInteger toX(double d, RoundingMode mode) Implements abstract com. Doc from com. Returns d's value as an X, rounded with the specified mode.
| |