Advertisement
Guest User

complex.h

a guest
Jan 12th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1.  
  2. #define _COMPLEX_H
  3.  
  4. /* COMPLEX.H header file       
  5.  * use for complex arithmetic in C
  6.  (part of them are from "C Tools for Scientists and Engineers" by L. Baker)
  7. */
  8. #define sin(%0) floatsin(%0)
  9. #define cos(%0) floatcos(%0)
  10. enum __COMPLEX{ %0 x,y; };
  11. typedef enum __COMPLEX COMPLEX;
  12.  
  13. /* for below, X, Y are complex structures, and one is returned */
  14.  
  15. /*//real part of the complex multiplication */
  16. #define CMULTR(X,Y) ((X).x*(Y).x-(X).y*(Y).y)
  17. /*//image part of the complex multiplication */
  18. #define CMULTI(X,Y) ((X).y*(Y).x+(X).x*(Y).y)
  19. /*// used in the Division : real part of the division */
  20. #define CDRN(X,Y) ((X).x*(Y).x+(Y).y*(X).y)
  21. /*// used in the Division : image part of the division */
  22. #define CDIN(X,Y) ((X).y*(Y).x-(X).x*(Y).y)
  23. /*// used in the Division : denumerator of the division */
  24. #define CNORM(X) ((X).x*(X).x+(X).y*(X).y)
  25. /*//real part of the complex */
  26. #define CREAL(X) ((%0)((X).x))
  27. /*//conjunction value */
  28. #define CONJG(z,X) {(z).x=(X).x;(z).y= -(X).y;}
  29. /*//conjunction value */
  30. #define CONJ(X) {(X).y= -(X).y;}
  31. /*//muliply : z could not be same variable as X or Y, same rule for other Macro */
  32. #define CMULT(z,X,Y) {(z).x=CMULTR((X),(Y));(z).y=CMULTI((X),(Y));}
  33. /*//division */
  34. #define CDIV(z,X,Y){%0 d=CNORM(Y); (z).x=CDRN(X,Y)/d; (z).y=CDIN(X,Y)/d;}
  35. /*//addition */
  36. #define CADD(z,X,Y) {(z).x=(X).x+(Y).x;(z).y=(X).y+(Y).y;}
  37. /*//subtraction */
  38. #define CSUB(z,X,Y) {(z).x=(X).x-(Y).x;(z).y=(X).y-(Y).y;}
  39. /*//assign */
  40. #define CLET(to,from) {(to).x=(from).x;(to).y=(from).y;}
  41. /*//abstract value(magnitude) */
  42. #define cabs(X) sqrt((X).y*(X).y+(X).x*(X).x)
  43. /*//real to complex */
  44. #define CMPLX(X,real,imag) {(X).x=(real);(X).y=(imag);}
  45. /*//multiply with real */
  46. #define CTREAL(z,X,real) {(z).x=(X).x*(real);(z).y=(X).y*(real);}
  47.  
  48. #define CEXP(z,phase) {(z).x = cos(phase); (z).y = sin(phase); }
  49. /* implementation using function : for compatibility */
  50. COMPLEX compdiv(COMPLEX ne,COMPLEX de);
  51. COMPLEX compexp(%0 theta);
  52. COMPLEX compmult(%0 scalar,COMPLEX compnum);
  53. COMPLEX compprod(COMPLEX compnum1, COMPLEX compnum2);
  54. COMPLEX comp2sum(COMPLEX summand1, COMPLEX summand2);
  55. COMPLEX comp3sum(COMPLEX summand1, COMPLEX summand2, COMPLEX summand3);
  56. COMPLEX compsubtract(COMPLEX complexA, COMPLEX complexB);
  57. %0  REAL(COMPLEX compnum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement