#include #define RESOLUTION 5000 void set_fpu (unsigned int mode) { asm ("fldcw %0" : : "m" (*&mode)); } class Complex { public: Complex(double xc,double yc) : x(xc), y(yc) { } double norm_square() { return x*x+y*y; } Complex operator*(const Complex &other) { return Complex(x*other.x-y*other.y, x*other.y+y*other.x); } Complex operator+(const Complex &other) { return Complex(x + other.x, y + other.y); } private: double x; double y; }; class Complex2 { public: Complex2(double xc,double yc) : x(xc), y(yc) { } double norm_square() { return x*x+y*y; } template Complex2 operator*(const T &other) { return Complex2(x*other.x-y*other.y, x*other.y+y*other.x); } template Complex2 operator+(const T &other) { return Complex2(x + other.x, y + other.y); } private: double x; double y; }; int iters1(int max_iter,double xc,double yc) { double x = xc; double y = yc; for(int count = 0;count= 4.0) { return count; } double tmp = x*x-y*y+xc; y = 2.0 * x * y + yc; x = tmp; } return max_iter; } int iters2(int max_iter,double xc,double yc) { Complex c(xc,yc); Complex z(xc,yc); for(int count = 0;count= 4.0 ) { return count; } z = z * z + c; } return max_iter; } int iters3(int max_iter,double xc,double yc) { Complex2 c(xc,yc); Complex2 z(xc,yc); for(int count = 0;count= 4.0 ) { return count; } z = z * z + c; } return max_iter; } int main() { set_fpu (0x27F); int max_val = RESOLUTION/2; int min_val = -max_val; double mul = 2.0 / max_val; int count = 0; for(int i=min_val;i<=max_val;i++) { for(int j=min_val;j<=max_val;j++) { count += iters1(100,mul*i,mul*j); // Replace this call by iters[2,3] } } printf("result: %d\n",count); }