mightymandel v16

GPU-based Mandelbrot set explorer

complex.h
Go to the documentation of this file.
1 // mightymandel -- GPU-based Mandelbrot Set explorer
2 // Copyright (C) 2012,2013,2014 Claude Heiland-Allen
3 // License GPL3+ http://www.gnu.org/licenses/gpl.html
4 
5 #ifndef COMPLEX_H
6 #define COMPLEX_H 1
7 
17 #include <mpfr.h>
18 
22 typedef mpfr_t R;
23 
27 typedef struct {
28  R x;
29  R y;
30 } C;
31 
38 #define c_set_prec(o, p) do{\
39  mpfr_set_prec(o.x, p);\
40  mpfr_set_prec(o.y, p);\
41 }while(0)
42 
49 #define c_set(o, l) do{\
50  mpfr_set(o.x, l.x, MPFR_RNDN);\
51  mpfr_set(o.y, l.y, MPFR_RNDN);\
52 }while(0)
53 
62 #define c_mag2(o, l, t1, t2) do{\
63  mpfr_sqr(t1, l.x, MPFR_RNDN);\
64  mpfr_sqr(t2, l.y, MPFR_RNDN);\
65  mpfr_add(o, t1, t2, MPFR_RNDN);\
66 }while(0)
67 
75 #define c_add(o, l, r) do{\
76  mpfr_add(o.x, l.x, r.x, MPFR_RNDN);\
77  mpfr_add(o.y, l.y, r.y, MPFR_RNDN);\
78 }while(0)
79 
89 #define c_sqr(o, l, t1, t2, t3) do{\
90  mpfr_sqr(t1, l.x, MPFR_RNDN);\
91  mpfr_sqr(t2, l.y, MPFR_RNDN);\
92  mpfr_mul(t3, l.x, l.y, MPFR_RNDN);\
93  mpfr_sub(o.x, t1, t2, MPFR_RNDN);\
94  mpfr_mul_2ui(o.y, t3, 1, MPFR_RNDN);\
95 }while(0)
96 
108 #define c_mul(o, l, r, t1, t2, t3, t4) do{\
109  mpfr_mul(t1, l.x, r.x, MPFR_RNDN);\
110  mpfr_mul(t2, l.y, r.y, MPFR_RNDN);\
111  mpfr_mul(t3, l.x, r.y, MPFR_RNDN);\
112  mpfr_mul(t4, l.y, r.x, MPFR_RNDN);\
113  mpfr_sub(o.x, t1, t2, MPFR_RNDN);\
114  mpfr_add(o.y, t3, t4, MPFR_RNDN);\
115 }while(0)
116 
124 #define c_mul_2ui(o, l, r) do{\
125  mpfr_mul_2ui(o.x, l.x, r, MPFR_RNDN);\
126  mpfr_mul_2ui(o.y, l.y, r, MPFR_RNDN);\
127 }while(0)
128 
129 #endif