sqrtToInt method

int sqrtToInt()

Returns the square root of this as an int, but only if this is a valid square, otherwise throws an InvalidPowerException.

Implementation

int sqrtToInt() {
  final sqrt = this.sqrt();

  if (!sqrt.isValidInteger) {
    throw (InvalidPowerException(2, this));
  }

  return sqrt.toInt();
}