isPrime method

bool isPrime({
  1. int millerRabinReps = 20,
})

Implementation

bool isPrime({int millerRabinReps = 20}) {
  if (this == BigInt.two) return true;
  if (isEven) return false;

  if (this <= BigInt.from(smallPrimes.last)) {
    return smallPrimes.contains(toInt());
  }

  final mod = this % smallPrimesProduct;

  for (final prime in smallPrimes) {
    if (mod % BigInt.from(prime) == BigInt.zero) {
      return false;
    }
  }

  if (!probablyPrimeMillerRabin(millerRabinReps)) return false;
  // TODO if (!probablyPrimeLucas()) return false;

  return true;
}