int single_mandelbrot_point(complex_t coord_point, complex_t c_constant, int Max_iterations, double divergent_limit) { complex_t z_point; /* we need a point to use in our calculation */ int num_iterations; /* a counter to track the number of iterations done */ num_iterations = 0; /* zero our counter */ z_point = coord_point; /* initialize to the given start coordinate */ /* loop while the absolute value of the complex coordinate is < our limit (for a mandelbrot) or until we've done our specified maximum number of iterations (both julia and mandelbrot) */ while (absolute_complex(z_point) < divergent_limit && num_iterations < Max_iterations) { /* z = z*z + c */ z_point = multiply_complex(z_point,z_point); z_point = add_complex(z_point,c_constant); ++num_iterations; } /* done iterating for one point */ return num_iterations; }
//--------------------------------------------------------------------------------------------------- int main(){ complex c1 ={1.0,2.0,}; complex c2 = {2.0,3.0,}; complex c3 = add_complex(c1,c2); complex c4 = minus_complex(c1,c2); complex c5 = multiply_complex(c1,c2); complex c6 = div_complex(c1,c2); printf("c1 + c2 = (%f,%f)\n",c3.x,c3.y); printf("c1 - c2 = (%f,%f)\n",c4.x,c4.y); printf("c1 * c2 = (%f,%f)\n",c5.x,c5.y); printf("c1 / c2 = (%f,%f)\n",c6.x,c6.y); return 0; }
int main(void) { complex x, y, z, z2; /* 二つの複素数に値を代入 */ x.real = 3.0; x.imaginary = 2.0; y.real = 1.0; y.imaginary = -4.0; ShowComplex("s", x); ShowComplex("t", y); z = add_complex(x, y); /* 複素数の和を z に代入 */ ShowComplex("s + t", z); z2 = multiply_complex(x, z); /* 複素数の積を z に代入 */ ShowComplex("s(s + t)", z2); }