Big Integers

The BigInteger type provides arbitrary-precision whole numbers. Unlike the standard 64-bit Integer, a BigInteger can grow to represent any value, limited only by the available system memory.

Usage

Big integers are essential for cryptography, high-precision scientific calculations, or any domain where values might exceed the $2^{63}-1$ limit of standard integers.

var big := BigInteger('1234567890123456789012345678901234567890');
big := big * 2;

PrintLn(big.ToString);
Result
2469135780246913578024691357802469135780

Literals & Initialization

While there is no native "BigInt" literal suffix (like 100n in JS), you can initialize them from strings or standard integers using the BigInteger() constructor-style call.

var b1 := BigInteger(100);
var b2 := BigInteger('1' + '0'.Dupe(50)); // 1 followed by 50 zeros

PrintLn(b1.ToString);
Result
100

Operations

BigInteger supports all standard arithmetic and comparison operators.

  • Arithmetic: +, -, *, div, mod
  • Comparison: =, <>, <, >, <=, >=
  • Bitwise: and, or, xor, not, shl, shr
var a := BigInteger(1000);
var b := BigInteger(3);

var res := (a div b); // 333
PrintLn(res.ToString);
Result
333

Method Helpers

The BigInteger type includes several useful methods for common mathematical operations.

  • IsEven / IsOdd: Check parity.
  • IsPrime: Checks if the number is prime (probabilistic for large numbers).
  • Abs: Returns the absolute value.
  • Pow(exponent): Raises the number to a power.
  • ModPow(exponent, modulus): Efficient modular exponentiation (critical for RSA/DH).
  • Gcd(other): Greatest Common Divisor.

Related Reference

For a complete list of BigInteger methods, see the Math API Reference.

On this page