/// <summary> /// Mandelbrot calculations, optimized. /// Gains a speed factor 3.1 compared to a lazy 'c# with GMP Real' implementation. /// /// Calculates: /// tmp = 2*x*y + y0 /// x = x*x - y*y + x0 /// y = tmp /// /// Remarks: All Parameters must be properly created. /// /// Example implementation, calculates one pixel: /// /// int iterations = 0; /// Real x0 = new Real(your x coordinate); /// Real y0 = new Real(your y coordinate); /// Real x = new Real(x0); /// Real y = new Real(y0); /// Real temp = new Real(); /// /// while ((iterations < maxIterations) && (x.DoubleValue * x.DoubleValue + y.DoubleValue * y.DoubleValue <= 4)) /// { /// Real.MandelbrotOperations(ref x, ref y, ref x0, ref y0, ref temp); /// iteration++; /// } /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="x0"></param> /// <param name="y0"></param> public static void MandelbrotOperations(ref Real x, ref Real y, ref Real x0, ref Real y0, ref Real tmp) { // t = 2*x*y+y0 mpf_mul(ref tmp._pointer, ref x._pointer, ref y._pointer); mpf_mul_ui(ref tmp._pointer, ref tmp._pointer, (uint)2); mpf_add(ref tmp._pointer, ref tmp._pointer, ref y0._pointer); // x = x*x - y*y + x0 mpf_mul(ref y._pointer, ref y._pointer, ref y._pointer); // y = y*y mpf_mul(ref x._pointer, ref x._pointer, ref x._pointer); // x = x*x mpf_sub(ref x._pointer, ref x._pointer, ref y._pointer); // x = x-y mpf_add(ref x._pointer, ref x._pointer, ref x0._pointer); // x = x+x0 // exchange y and t the FAST way :) mpf_t temp_mpf_t = y._pointer; y._pointer = tmp._pointer; tmp._pointer = temp_mpf_t; }
private static extern void mpf_init(ref mpf_t ptr);
private static extern void mpf_neg(ref mpf_t rop, ref mpf_t op);
private static extern void mpf_sqrt_ui(ref mpf_t rop, uint op);
private static extern int mpf_integer_p(ref mpf_t op);
private static extern int mpf_floor(ref mpf_t rop, ref mpf_t op);
private static extern int mpf_cmp_ui(ref mpf_t op1, uint op2);
private static extern int mpf_cmp_d(ref mpf_t op1, double op2);
private static extern void mpf_init_set(ref mpf_t rop, ref mpf_t op);
private static extern int mpf_swap(ref mpf_t rop1, ref mpf_t rop2);
private static extern void mpf_set_z(ref mpf_t rop, ref mpz_t op);
private static extern void mpf_set_prec(ref mpf_t ptr, uint prec);
private static extern uint mpf_get_prec(ref mpf_t ptr);
private static extern void mpf_clear(ref mpf_t ptr);
private static extern void mpf_init2(ref mpf_t ptr, uint prec);
private static extern void mpf_ui_div(ref mpf_t rop, uint op1, ref mpf_t op2);
private static extern int mpf_cmp(ref mpf_t op1, ref mpf_t op2);
private static extern void mpf_init_set_si(ref mpf_t rop, int op);
private static extern int mpf_cmp_si(ref mpf_t op1, int op2);
private static extern void mpf_init_set_d(ref mpf_t rop, double op);
private static extern void mpf_ceil(ref mpf_t rop, ref mpf_t op);
private static extern int mpf_init_set_str(ref mpf_t rop, IntPtr s, int sbase);
private static extern int mpf_trunc(ref mpf_t rop, ref mpf_t op);
private static extern double mpf_get_d(ref mpf_t op);
private static extern void mpf_sqrt(ref mpf_t rop, ref mpf_t op);
private static extern int mpf_get_si(ref mpf_t op);
private static extern void mpf_pow_ui(ref mpf_t rop, ref mpf_t op1, uint op2);
private static extern IntPtr mpf_get_str(IntPtr s, ref int expptr, int sbase, int ndigits, ref mpf_t op);
private static extern void mpq_set_f(ref mpq_t rop, ref mpf_t op);
private static extern void mpf_mul(ref mpf_t rop, ref mpf_t op1, ref mpf_t op2);