biginteger

How large can a Java BigInteger be?

Java FAQ: How large can a Java BigInteger be?

Answer: The Java BigInteger Scaladoc states the following:

“BigInteger must support values in the range -2Integer.MAX_VALUE (exclusive) to +2Integer.MAX_VALUE (exclusive) and may support values outside of that range.”

The Scala BigInt wraps Java’s BigInteger, so it will also have the same data range.

How to handle very large numbers in Scala (BigInt, BigDecimal)

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 2.6, “Handling Very Large Numbers in Scala.”

Problem

You’re writing a Scala application and need to use very large integer or decimal numbers.

Solution

Use the Scala BigInt and BigDecimal classes. You can create a BigInt: