昨天我创建了这段可以计算z ^ n的代码,其中z是一个复数,n是任何正整数.
--snip--
float real = 0;
float imag = 0;
// d is the power the number is raised to [(x + yi)^d]
for (int n = 0; n <= d; n++) {
if (n == 0) {
real += pow(a, d);
} else { // binomial theorem
switch (n % 4) {
case 1: // i
imag += bCo(d, n) * pow(a, d - n) * pow(b, n);
break;
case 2: // -1
real -= bCo(d, n) …Run Code Online (Sandbox Code Playgroud)