nthRoot function

dynamic nthRoot(
  1. dynamic x,
  2. dynamic nth
)

Returns the nth root of a number.

Example:

// The cube root of 8 will be:
print(nthRoot(8, 3));  // Output: 2.0

Implementation

dynamic nthRoot(dynamic x, dynamic nth) {
  if (x is num || x is Complex) {
    return Complex(x).nthRoot(nth.toInt());
  } else if (x is Matrix) {
    return MatrixFunctions(x).nthRoot(nth.toInt());
  } else {
    throw ArgumentError('Input should be either num or Complex');
  }
}