BigIntegerMath is used to perform mathematical operations on BigInteger values. Basic standalone math functions are divided into the classes IntMath, LongMath, DoubleMath, and BigIntegerMath based on the primary numeric type involved. These classes have parallel structure, but each supports only the relevant subset of functions. Similar functionality for int and for long can be found in IntMath and LongMath respectively.
Declaration : The declaration for com.google.common.math.BigIntegerMath class is :
@GwtCompatible(emulated = true) public final class BigIntegerMath extends Object
Below table shows the methods provided by BigIntegerMath Class of Guava :
- log2 : IllegalArgumentException if x <= 0
- log10 : IllegalArgumentException if x <= 0
- sqrt : IllegalArgumentException if x < 0
- divide : ArithmeticException if q == 0, or if mode == UNNECESSARY and a is not an integer multiple of b
- factorial : IllegalArgumentException if n < 0
- binomial : IllegalArgumentException if n < 0, k n
Example 1 :
Error Message is : Rounding necessary
Example 2 :
2 Log10 is : 3 factorial is : 5040 Log2 is : 3 sqrt is : 10
Reference : Google Guava
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.