home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / numana01.zip / DEF / CX.DEF < prev    next >
Text File  |  1996-07-29  |  3KB  |  94 lines

  1. DEFINITION MODULE Cx;
  2.  
  3.         (********************************************************)
  4.         (*                                                      *)
  5.         (*              Complex number arithmetic               *)
  6.         (*                                                      *)
  7.         (*  Programmer:         P. Moylan                       *)
  8.         (*  Last edited:        29 July 1996                    *)
  9.         (*  Status:             OK                              *)
  10.         (*                                                      *)
  11.         (*      This version takes advantage of the ISO M2      *)
  12.         (*      built-in LONGCOMPLEX type.  Strictly speaking   *)
  13.         (*      this module is not necessary at all, but it's   *)
  14.         (*      here to simplify porting from non-ISO compilers.*)
  15.         (*                                                      *)
  16.         (********************************************************)
  17.  
  18. TYPE Complex = LONGCOMPLEX;
  19.  
  20. (************************************************************************)
  21.  
  22. PROCEDURE Cmplx (x, y: LONGREAL): Complex;
  23.  
  24.     (* Returns x + iy. *)
  25.  
  26. PROCEDURE Re (Z: Complex): LONGREAL;
  27.  
  28.     (* Returns the real part of Z. *)
  29.  
  30. PROCEDURE Im (Z: Complex): LONGREAL;
  31.  
  32.     (* Returns the imaginary part of Z. *)
  33.  
  34. PROCEDURE Magnitude (Z: Complex): LONGREAL;
  35.  
  36.     (* Returns the magnitude of Z. *)
  37.  
  38. PROCEDURE Phase (Z: Complex): LONGREAL;
  39.  
  40.     (* Returns the phase (angle) of Z.  The result is in the range      *)
  41.     (* -PI to +PI, but never exactly equal to -PI.                      *)
  42.  
  43. PROCEDURE Conjg (Z: Complex): Complex;
  44.  
  45.     (* Returns the complex conjugate of Z. *)
  46.  
  47. PROCEDURE Add (A, B: Complex): Complex;
  48.  
  49.     (* Computes A + B. *)
  50.  
  51. PROCEDURE Sub (A, B: Complex): Complex;
  52.  
  53.     (* Computes A - B. *)
  54.  
  55. PROCEDURE Mul (A, B: Complex): Complex;
  56.  
  57.     (* Computes A*B. *)
  58.  
  59. PROCEDURE RMul (A: LONGREAL;  B: Complex): Complex;
  60.  
  61.     (* Multiplication by a real number. *)
  62.  
  63. PROCEDURE Div (A, B: Complex): Complex;
  64.  
  65.     (* Computes A/B. *)
  66.  
  67. PROCEDURE Sqt (Z: Complex): Complex;
  68.  
  69.     (* Returns the square root of Z. *)
  70.  
  71. PROCEDURE Cln (Z: Complex): Complex;
  72.  
  73.     (* Complex logarithm (untested. *)
  74.  
  75. PROCEDURE Cexp (Z: Complex): Complex;
  76.  
  77.     (* Complex exponential. *)
  78.  
  79. PROCEDURE Csin (Z: Complex): Complex;
  80.  
  81.     (* Complex sine (untested). *)
  82.  
  83. PROCEDURE Ccos (Z: Complex): Complex;
  84.  
  85.     (* Complex cosine (untested). *)
  86.  
  87. PROCEDURE Write (Z: Complex;  places: CARDINAL);
  88.  
  89.     (* Writes Z in Cartesian form, with "places" characters allowed     *)
  90.     (* for each of the real and imaginary parts.                        *)
  91.  
  92. END Cx.
  93.  
  94.