Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _COMPLEX_H
- /* COMPLEX.H header file
- * use for complex arithmetic in C
- (part of them are from "C Tools for Scientists and Engineers" by L. Baker)
- */
- #define sin(%0) floatsin(%0)
- #define cos(%0) floatcos(%0)
- enum __COMPLEX{ %0 x,y; };
- typedef enum __COMPLEX COMPLEX;
- /* for below, X, Y are complex structures, and one is returned */
- /*//real part of the complex multiplication */
- #define CMULTR(X,Y) ((X).x*(Y).x-(X).y*(Y).y)
- /*//image part of the complex multiplication */
- #define CMULTI(X,Y) ((X).y*(Y).x+(X).x*(Y).y)
- /*// used in the Division : real part of the division */
- #define CDRN(X,Y) ((X).x*(Y).x+(Y).y*(X).y)
- /*// used in the Division : image part of the division */
- #define CDIN(X,Y) ((X).y*(Y).x-(X).x*(Y).y)
- /*// used in the Division : denumerator of the division */
- #define CNORM(X) ((X).x*(X).x+(X).y*(X).y)
- /*//real part of the complex */
- #define CREAL(X) ((%0)((X).x))
- /*//conjunction value */
- #define CONJG(z,X) {(z).x=(X).x;(z).y= -(X).y;}
- /*//conjunction value */
- #define CONJ(X) {(X).y= -(X).y;}
- /*//muliply : z could not be same variable as X or Y, same rule for other Macro */
- #define CMULT(z,X,Y) {(z).x=CMULTR((X),(Y));(z).y=CMULTI((X),(Y));}
- /*//division */
- #define CDIV(z,X,Y){%0 d=CNORM(Y); (z).x=CDRN(X,Y)/d; (z).y=CDIN(X,Y)/d;}
- /*//addition */
- #define CADD(z,X,Y) {(z).x=(X).x+(Y).x;(z).y=(X).y+(Y).y;}
- /*//subtraction */
- #define CSUB(z,X,Y) {(z).x=(X).x-(Y).x;(z).y=(X).y-(Y).y;}
- /*//assign */
- #define CLET(to,from) {(to).x=(from).x;(to).y=(from).y;}
- /*//abstract value(magnitude) */
- #define cabs(X) sqrt((X).y*(X).y+(X).x*(X).x)
- /*//real to complex */
- #define CMPLX(X,real,imag) {(X).x=(real);(X).y=(imag);}
- /*//multiply with real */
- #define CTREAL(z,X,real) {(z).x=(X).x*(real);(z).y=(X).y*(real);}
- #define CEXP(z,phase) {(z).x = cos(phase); (z).y = sin(phase); }
- /* implementation using function : for compatibility */
- COMPLEX compdiv(COMPLEX ne,COMPLEX de);
- COMPLEX compexp(%0 theta);
- COMPLEX compmult(%0 scalar,COMPLEX compnum);
- COMPLEX compprod(COMPLEX compnum1, COMPLEX compnum2);
- COMPLEX comp2sum(COMPLEX summand1, COMPLEX summand2);
- COMPLEX comp3sum(COMPLEX summand1, COMPLEX summand2, COMPLEX summand3);
- COMPLEX compsubtract(COMPLEX complexA, COMPLEX complexB);
- %0 REAL(COMPLEX compnum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement