BigIntegerMath提供BigInteger的实用方法。

## 类声明

```@GwtCompatible(emulated=true)
public final class BigIntegerMath
extends Object```

## 方法

S.N. 方法及说明
1 static BigInteger binomial(int n, int k)

2 static BigInteger divide(BigInteger p, BigInteger q, RoundingMode mode)

3 static BigInteger factorial(int n)

4 static boolean isPowerOfTwo(BigInteger x)

5 static int log10(BigInteger x, RoundingMode mode)

6 static int log2(BigInteger x, RoundingMode mode)

7 static BigInteger sqrt(BigInteger x, RoundingMode mode)

## 继承的方法

• java.lang.Object

## BigIntegerMath 示例

GuavaTester.java
```import java.math.BigInteger;
import java.math.RoundingMode;

public class GuavaTester {

public static void main(String args[]){
GuavaTester tester = new GuavaTester();
tester.testBigIntegerMath();
}
private void testBigIntegerMath(){
System.out.println(BigIntegerMath.divide(BigInteger.TEN, new BigInteger("2"), RoundingMode.UNNECESSARY));
try{
//exception will be thrown as 100 is not completely divisible by 3 thus rounding
// is required, and RoundingMode is set as UNNESSARY
System.out.println(BigIntegerMath.divide(BigInteger.TEN, new BigInteger("3"), RoundingMode.UNNECESSARY));
}catch(ArithmeticException e){
System.out.println("Error: " + e.getMessage());
}

System.out.println("Log2(2): "+BigIntegerMath.log2(new BigInteger("2"), RoundingMode.HALF_EVEN));

System.out.println("Log10(10): "+BigIntegerMath.log10(BigInteger.TEN, RoundingMode.HALF_EVEN));

System.out.println("sqrt(100): "+BigIntegerMath.sqrt(BigInteger.TEN.multiply(BigInteger.TEN), RoundingMode.HALF_EVEN));

System.out.println("factorial(5): "+BigIntegerMath.factorial(5));
}
}```

## 验证结果

```C:\Guava>javac GuavaTester.java
```

```C:\Guava>java GuavaTester
```

```5
Error: Rounding necessary
Log2(2): 1
Log10(10): 1
sqrt(100): 10
factorial(5): 120```