x raised to the power of n
import std.math.operations : isClose; auto a = complex(1.0, 2.0); assert(pow(a, 2) == a * a); assert(pow(a, 3) == a * a * a); assert(pow(a, -2) == 1.0 / (a * a)); assert(isClose(pow(a, -3), 1.0 / (a * a * a)));
import std.math.operations : isClose; assert(pow(complex(0.0), 2.0) == complex(0.0)); assert(pow(complex(5.0), 2.0) == complex(25.0)); auto a = pow(complex(-1.0, 0.0), 0.5); assert(isClose(a, complex(0.0, +1.0), 0.0, 1e-16)); auto b = pow(complex(-1.0, -0.0), 0.5); assert(isClose(b, complex(0.0, -1.0), 0.0, 1e-16));
import std.math.operations : isClose; import std.math.exponential : exp; import std.math.constants : PI; auto a = complex(0.0); auto b = complex(2.0); assert(pow(a, b) == complex(0.0)); auto c = complex(0.0L, 1.0L); assert(isClose(pow(c, c), exp((-PI) / 2)));
import std.math.operations : isClose; assert(pow(2.0, complex(0.0)) == complex(1.0)); assert(pow(2.0, complex(5.0)) == complex(32.0)); auto a = pow(-2.0, complex(-1.0)); assert(isClose(a, complex(-0.5), 0.0, 1e-16)); auto b = pow(-0.5, complex(-1.0)); assert(isClose(b, complex(-2.0), 0.0, 1e-15));
Calculates xn. The branch cut is on the negative axis.