Package com.google.common.math
Class BigIntegerMath
java.lang.Object
com.google.common.math.BigIntegerMath
@GwtCompatible(emulated=true)
@Deprecated(since="2022-12-01")
public final class BigIntegerMath
extends Object
Deprecated.
The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023
A class for arithmetic on values of type
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.
- Since:
- 11.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic BigInteger
binomial
(int n, int k) Deprecated.Returnsn
choosek
, also known as the binomial coefficient ofn
andk
, that is,n! / (k! (n - k)!)
.static BigInteger
divide
(BigInteger p, BigInteger q, RoundingMode mode) Deprecated.Returns the result of dividingp
byq
, rounding using the specifiedRoundingMode
.static BigInteger
factorial
(int n) Deprecated.Returnsn!
, that is, the product of the firstn
positive integers, or1
ifn == 0
.static boolean
Deprecated.Returnstrue
ifx
represents a power of two.static int
log10
(BigInteger x, RoundingMode mode) Deprecated.Returns the base-10 logarithm ofx
, rounded according to the specified rounding mode.static int
log2
(BigInteger x, RoundingMode mode) Deprecated.Returns the base-2 logarithm ofx
, rounded according to the specified rounding mode.static BigInteger
sqrt
(BigInteger x, RoundingMode mode) Deprecated.Returns the square root ofx
, rounded with the specified rounding mode.
-
Method Details
-
isPowerOfTwo
Deprecated.Returnstrue
ifx
represents a power of two. -
log2
Deprecated.Returns the base-2 logarithm ofx
, rounded according to the specified rounding mode.- Throws:
IllegalArgumentException
- ifx <= 0
ArithmeticException
- ifmode
isRoundingMode.UNNECESSARY
andx
is not a power of two
-
log10
Deprecated.Returns the base-10 logarithm ofx
, rounded according to the specified rounding mode.- Throws:
IllegalArgumentException
- ifx <= 0
ArithmeticException
- ifmode
isRoundingMode.UNNECESSARY
andx
is not a power of ten
-
sqrt
Deprecated.Returns the square root ofx
, rounded with the specified rounding mode.- Throws:
IllegalArgumentException
- ifx < 0
ArithmeticException
- ifmode
isRoundingMode.UNNECESSARY
andsqrt(x)
is not an integer
-
divide
@GwtIncompatible("TODO") public static BigInteger divide(BigInteger p, BigInteger q, RoundingMode mode) Deprecated.Returns the result of dividingp
byq
, rounding using the specifiedRoundingMode
.- Throws:
ArithmeticException
- ifq == 0
, or ifmode == UNNECESSARY
anda
is not an integer multiple ofb
-
factorial
Deprecated.Returnsn!
, that is, the product of the firstn
positive integers, or1
ifn == 0
.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).
- Throws:
IllegalArgumentException
- ifn < 0
-
binomial
Deprecated.Returnsn
choosek
, also known as the binomial coefficient ofn
andk
, that is,n! / (k! (n - k)!)
.Warning: the result can take as much as O(k log n) space.
- Throws:
IllegalArgumentException
- ifn < 0
,k < 0
, ork > n
-