pow function
dynamic
pow(
- dynamic x,
- dynamic exponent
Raises a number to the power of another number.
Example 1:
print(pow(2, 3)); // Output: 8.0
Example 2:
var xxx = Complex(1, 2);
print(pow(2, xxx)); // Output: 0.36691394948660344 + 1.9660554808224875i
Implementation
dynamic pow(dynamic x, dynamic exponent) {
if (x is Expression || exponent is Expression) {
final base = x is Expression ? x : Literal(x);
final exp = exponent is Expression ? exponent : Literal(exponent);
return Pow(base, exp);
}
if (x is num || x is Complex) return Complex(x).pow(exponent);
if (x is Matrix) return MatrixFunctions(x).pow(exponent);
throw ArgumentError('Input should be num, Complex, Matrix, or Expression');
}