1 /* 2 * XaoS, a fast portable realtime fractal zoomer 3 * Copyright (C) 1996,1997 by 4 * 5 * Jan Hubicka (hubicka@paru.cas.cz) 6 * Thomas Marsh (tmarsh@austin.ibm.com) 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 */ 22 #ifndef COMPLEX_H 23 #define COMPLEX_H 24 25 #define c_add_rp(ar,ai,br,bi) ((ar)+(br)) 26 #define c_add_ip(ar,ai,br,bi) ((ai)+(bi)) 27 #define c_add(ar,ai,br,bi,or,oi) ((or)=(ar)+(br),(oi)=(ai)+(bi)) 28 29 #define c_sub_rp(ar,ai,br,bi) ((ar)-(br)) 30 #define c_sub_ip(ar,ai,br,bi) ((ai)-(bi)) 31 #define c_sub(ar,ai,br,bi,or,oi) ((or)=(ar)-(br),(oi)=(ai)-(bi)) 32 33 #define c_mul(ar,ai,br,bi,or,oi) ((or)=(ar)*(br)-(ai)*(bi),(oi)=((ar)*(bi))+((ai)*(br))) 34 #define c_mul_rp(ar,ai,br,bi) ((ar)*(br)-(ai)*(bi)) 35 #define c_mul_ip(ar,ai,br,bi) ((ar)*(bi)+(ai)*(br)) 36 37 #define c_div_rp(ar,ai,br,bi) (((ar) * (br) + (ai) * (bi))/ ((bi) * (bi) + (br) * (br))) 38 #define c_div_ip(ar,ai,br,bi) ((-(ar) * (bi) + (ai) * (br)) / ((br) * (br) + (bi) * (bi))) 39 #define c_div(ar,ai,br,bi,or,oi) ((or)=c_div_rp(ar,ai,br,bi),(oi)=c_div_ip(ar,ai,br,bi)) 40 41 #define c_pow2_rp(ar,ai) ((ar)*(ar)-(ai)*(ai)) 42 #define c_pow2_ip(ar,ai) (2*(ar)*(ai)) 43 #define c_pow2(ar,ai,or,oi) ((or)=c_pow2_rp(ar,ai),(oi)=c_pow2_ip(ar,ai)) 44 45 #define c_pow3_rp(ar,ai) ((ar)*(ar)*(ar)-3*(ar)*(ai)*(ai)) 46 #define c_pow3_ip(ar,ai) (3*(ar)*(ar)*(ai)-(ai)*(ai)*(ai)) 47 #define c_pow3(ar,ai,or,oi) ((or)=c_pow3_rp(ar,ai),(oi)=c_pow3_ip(ar,ai)) 48 49 #define c_pow4_rp(ar,ai) ((ar)*(ar)*(ar)*(ar)-6*(ar)*(ar)*(ai)*(ai)+(ai)*(ai)*(ai)*(ai)) 50 #define c_pow4_ip(ar,ai) (4*(ar)*(ar)*(ar)*(ai)-4*(ar)*(ai)*(ai)*(ai)) 51 #define c_pow4(ar,ai,or,oi) ((or)=c_pow4_rp(ar,ai),(oi)=c_pow4_ip(ar,ai)) 52 53 #define square(x,y) ((x)*(x)+(y)*(y)) 54 #define distance(x1,y1,x2,y2) square((x1)-(x2),(y1)-(y2)) 55 56 #define myabs(x) ((x)>0?(x):-(x)) 57 58 #define c_exp_rp(ar,ai) ((exp(ar))*(cos(ai))) 59 #define c_exp_ip(ar,ai) (sin(ai)) 60 #define c_exp(ar,ai,or,oi) ((or)=(c_exp_rp(ar,ai)),(oi)=(c_exp_ip(ar,ai))) 61 62 /* Complex sin(const Complex &v) 63 { Complex u, i; 64 i.c[0] = 0; 65 i.c[1] = 1; 66 u = (exp(i * v) - exp(i * (-v))) / (2 * i); 67 return u; } */ 68 69 #define c_sin(ar, ai, or, oi) \ 70 { number_t _c_tmp_r1, _c_tmp_i1; \ 71 number_t _c_tmp_r2, _c_tmp_i2; \ 72 number_t _c_tmp_r3, _c_tmp_i3; \ 73 c_mul(0,1,ar,ai,_c_tmp_r1,_c_tmp_i1); \ 74 c_exp(_c_tmp_r1,_c_tmp_i1,_c_tmp_r2,_c_tmp_i2); \ 75 c_mul(0,1,-ar,-ai,or,oi); \ 76 c_exp(or,oi,_c_tmp_r1,_c_tmp_i1); \ 77 c_sub(_c_tmp_r2,_c_tmp_i2,_c_tmp_r1,_c_tmp_i1,_c_tmp_r3,_c_tmp_i3); \ 78 c_mul(2,0,0,1,_c_tmp_r1,_c_tmp_i1); \ 79 c_div(_c_tmp_r3,_c_tmp_i3,_c_tmp_r1,_c_tmp_i1,or,oi); } 80 81 82 #endif /* COMPLEX_H */ 83