CKTIS / Java
math.BigInteger: practical reference
math.BigInteger: practical reference: BigInteger represents immutable arbitrary-precision integers and defines two-complement-style bit operations.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
java.math.BigIntegerBigInteger represents immutable arbitrary-precision integers and defines two-complement-style bit operations.
Use BigInteger for immutable integers beyond primitive ranges, including modular arithmetic, gcd, prime generation, and signed bit operations.
Division by zero throws ArithmeticException. mod requires a positive modulus and always returns a non-negative residue, whereas remainder follows signed integer remainder semantics.
Negative shift distances reverse the shift direction. There is no unsigned right shift because the two’s-complement model has conceptually infinite sign bits.
The example exercises the documented element in a small deterministic program and compares exact standard output.
Examples
public class Main {
public static void main(String[] args) throws Exception {
var value = new java.math.BigInteger("100000000000000000000").add(java.math.BigInteger.ONE);
System.out.println(value);
}
}
Result
100000000000000000001
The example exercises the documented element in a small deterministic program and compares exact standard output.