long. Where possible, methods are defined and
named analogously to their BigInteger counterparts.
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 BigInteger can be found in IntMath and BigIntegerMath respectively. For other common operations on long
values, see com..
| Modifier and Type | Class and Description |
|---|---|
| private static enum |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final int[] | |
| pack-priv static final int[] | |
| pack-priv static final long[] | |
| pack-priv static final long | |
| pack-priv static final long[] | |
| pack-priv static final long | MAX_POWER_OF_SQRT2_UNSIGNED
The biggest half power of two that fits into an unsigned long |
| pack-priv static final long | |
| pack-priv static final byte[] | |
| private static final long[][] | |
| pack-priv static final long[] | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static long | binomial(int n, int k)
Returns |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long | divide(long p, long q, RoundingMode mode)
Returns the result of dividing |
| public static long | |
| pack-priv static boolean | |
| public static long | |
| public static long | |
| public static boolean | |
| public static boolean | isPrime(long n)
Returns |
| pack-priv static int | |
| public static int | log10(long x, RoundingMode mode)
Returns the base-10 logarithm of |
| pack-priv static int | |
| public static int | log2(long x, RoundingMode mode)
Returns the base-2 logarithm of |
| public static long | |
| public static int | |
| public static long | |
| pack-priv static long | multiplyFraction(long x, long numerator, long denominator)
Returns (x * numerator / denominator), which is assumed to come out to an integral value. |
| public static long | |
| public static double | roundToDouble(long x, RoundingMode mode)
Returns |
| public static long | saturatedAdd(long a, long b)
Returns the sum of |
| public static long | saturatedMultiply(long a, long b)
Returns the product of |
| public static long | saturatedPow(long b, int k)
Returns the |
| public static long | saturatedSubtract(long a, long b)
Returns the difference of |
| public static long | sqrt(long x, RoundingMode mode)
Returns the square root of |
| biggestBinomials | back to summary |
|---|---|
| pack-priv static final int[] biggestBinomials | |
| biggestSimpleBinomials | back to summary |
|---|---|
| pack-priv static final int[] biggestSimpleBinomials
| |
| factorials | back to summary |
|---|---|
| pack-priv static final long[] factorials | |
| FLOOR_SQRT_MAX_LONG | back to summary |
|---|---|
| pack-priv static final long FLOOR_SQRT_MAX_LONG
| |
| halfPowersOf10 | back to summary |
|---|---|
| pack-priv static final long[] halfPowersOf10
| |
| MAX_POWER_OF_SQRT2_UNSIGNED | back to summary |
|---|---|
| pack-priv static final long MAX_POWER_OF_SQRT2_UNSIGNED The biggest half power of two that fits into an unsigned long | |
| MAX_SIGNED_POWER_OF_TWO | back to summary |
|---|---|
| pack-priv static final long MAX_SIGNED_POWER_OF_TWO
| |
| maxLog10ForLeadingZeros | back to summary |
|---|---|
| pack-priv static final byte[] maxLog10ForLeadingZeros
| |
| millerRabinBaseSets | back to summary |
|---|---|
| private static final long[][] millerRabinBaseSets | |
| powersOf10 | back to summary |
|---|---|
| pack-priv static final long[] powersOf10
| |
| SIEVE_30 | back to summary |
|---|---|
| private static final int SIEVE_30 | |
| LongMath | back to summary |
|---|---|
| private LongMath() | |
| binomial | back to summary |
|---|---|
| public static long binomial(int n, int k) Returns
| |
| ceilingPowerOfTwo | back to summary |
|---|---|
| public static long ceilingPowerOfTwo(long x) Returns the smallest power of two greater than or equal to
| |
| checkedAdd | back to summary |
|---|---|
| public static long checkedAdd(long a, long b) Returns the sum of
| |
| checkedMultiply | back to summary |
|---|---|
| public static long checkedMultiply(long a, long b) Returns the product of
| |
| checkedPow | back to summary |
|---|---|
| public static long checkedPow(long b, int k) Returns the
| |
| checkedSubtract | back to summary |
|---|---|
| public static long checkedSubtract(long a, long b) Returns the difference of
| |
| divide | back to summary |
|---|---|
| public static long divide(long p, long q, RoundingMode mode) Returns the result of dividing
| |
| factorial | back to summary |
|---|---|
| public static long factorial(int n) Returns
| |
| fitsInInt | back to summary |
|---|---|
| pack-priv static boolean fitsInInt(long x) | |
| floorPowerOfTwo | back to summary |
|---|---|
| public static long floorPowerOfTwo(long x) Returns the largest power of two less than or equal to
| |
| gcd | back to summary |
|---|---|
| public static long gcd(long a, long b) Returns the greatest common divisor of
| |
| isPowerOfTwo | back to summary |
|---|---|
| public static boolean isPowerOfTwo(long x) Returns This differs from
| |
| isPrime | back to summary |
|---|---|
| public static boolean isPrime(long n) Returns To test larger numbers, use
| |
| lessThanBranchFree | back to summary |
|---|---|
| pack-priv static int lessThanBranchFree(long x, long y) Returns 1 if
| |
| log10 | back to summary |
|---|---|
| public static int log10(long x, RoundingMode mode) Returns the base-10 logarithm of
| |
| log10Floor | back to summary |
|---|---|
pack-priv static int log10Floor(long x)
| |
| log2 | back to summary |
|---|---|
| public static int log2(long x, RoundingMode mode) Returns the base-2 logarithm of
| |
| mean | back to summary |
|---|---|
| public static long mean(long x, long y) Returns the arithmetic mean of
| |
| mod | back to summary |
|---|---|
| public static int mod(long x, int m) Returns For example:
| |
| mod | back to summary |
|---|---|
| public static long mod(long x, long m) Returns For example:
| |
| multiplyFraction | back to summary |
|---|---|
| pack-priv static long multiplyFraction(long x, long numerator, long denominator) Returns (x * numerator / denominator), which is assumed to come out to an integral value. | |
| pow | back to summary |
|---|---|
| public static long pow(long b, int k) Returns
| |
| roundToDouble | back to summary |
|---|---|
| public static double roundToDouble(long x, RoundingMode mode) Returns For the case of
| |
| saturatedAdd | back to summary |
|---|---|
| public static long saturatedAdd(long a, long b) Returns the sum of
| |
| saturatedMultiply | back to summary |
|---|---|
| public static long saturatedMultiply(long a, long b) Returns the product of
| |
| saturatedPow | back to summary |
|---|---|
| public static long saturatedPow(long b, int k) Returns the
| |
| saturatedSubtract | back to summary |
|---|---|
| public static long saturatedSubtract(long a, long b) Returns the difference of
| |
| sqrt | back to summary |
|---|---|
| public static long sqrt(long x, RoundingMode mode) Returns the square root of
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final LongMath. | LARGE
Works for all nonnegative signed longs. |
| public static final LongMath. | SMALL
Works for inputs ≤ FLOOR_SQRT_MAX_LONG. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv abstract long | |
| private long | |
| pack-priv abstract long | |
| pack-priv static boolean | |
| private boolean | testWitness(long base, long n)
Returns true if n is a strong probable prime relative to the specified base. |
| public static LongMath. | |
| public static LongMath. |
| LARGE | back to summary |
|---|---|
| public static final LongMath. Works for all nonnegative signed longs. | |
| SMALL | back to summary |
|---|---|
| public static final LongMath. Works for inputs ≤ FLOOR_SQRT_MAX_LONG. | |
| MillerRabinTester | back to summary |
|---|---|
| private MillerRabinTester() | |
| mulMod | back to summary |
|---|---|
| pack-priv abstract long mulMod(long a, long b, long m) Returns a * b mod m. | |
| powMod | back to summary |
|---|---|
| private long powMod(long a, long p, long m) Returns a^p mod m. | |
| squareMod | back to summary |
|---|---|
| pack-priv abstract long squareMod(long a, long m) Returns a^2 mod m. | |
| test | back to summary |
|---|---|
| pack-priv static boolean test(long base, long n) | |
| testWitness | back to summary |
|---|---|
| private boolean testWitness(long base, long n) Returns true if n is a strong probable prime relative to the specified base. | |
| valueOf | back to summary |
|---|---|
| public static LongMath. | |
| values | back to summary |
|---|---|
| public static LongMath. | |