isPrime property

bool isPrime

Checks if the number is a prime number. A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. Returns true if the number is prime, otherwise false.

Implementation

bool get isPrime {
  if (this <= 1) return false;
  for (int i = 2; i <= sqrt(this); i++) {
    if (this % i == 0) return false;
  }
  return true;
}