DEFINITION MODULE ComplexLib;
(*******************************************************************
Module ComplexLib (Version 0.5)
Copyright (c) 1987-2006 by Alex Itten and ETH Zurich.
Purpose Basic operations on complex variables using
extended reals (SANE).
Remarks There exist two implementations of this module
(Definition and Implementation). The present version
uses the SANE type Extended showing higher precision and
better convergence of the used Newton-Horner algorithm.
The alternative implementation uses the standard
type REAL and is about 10 times faster.
Programming
o Design
Alex Itten 22/05/1987
o Implementation
Alex Itten 22/05/1987
ETH Zurich
Systems Ecology
CHN E 35.1
Universitaetstrasse 16
8092 Zurich
SWITZERLAND
URLs:
<mailto:RAMSES@env.ethz.ch>
<http://www.sysecol.ethz.ch>
<http://www.sysecol.ethz.ch/SimSoftware/RAMSES>
Last revision of definition: 22/05/1987 AI
*******************************************************************)
FROM ExtMathLib IMPORT EXTREAL;
TYPE Complex = RECORD (* extended Type for intermediate *)
re,im : EXTREAL; (* results (80 Bit REAL) *)
END;
VAR (* The following variables are only read-omly variables ! use them only
as constants and for assignments *)
one, (* re:1. ; im:0. ); *)
zero, (* re:0. ; im:0. ); *)
imagUnit: Complex; (* re:0. ; im:1. ); *)
(* If you use consequently the following two procedures SetCom and
GetCom you will achieve to be independant from the implementation of
the type Complex (imaginary and real part of type REAL or EXTREAL). So it
will be possible to use either the MacMETH compiler 1.0 or 2.0 without
be forced to change the source code *)
PROCEDURE SetCom( VAR z: Complex; re,im: REAL);
(* Sets the real and imaginary part of an complex variable c to
the specified values. *)
PROCEDURE GetCom(z: Complex; VAR re,im: REAL);
(* Get the real and imaginary part of an complex variable c.
Use This procedure also to convert between ComplexLib.Complex and
ComplexLib.Complex if you need them both *)
(* basic operations on the type Complex *)
PROCEDURE PolToKart(betr,phi: REAL; VAR z:Complex);
(* Conversion of a Complex variable from the polar to the cartesian
description. *)
PROCEDURE KartToPol(z:Complex; VAR betr,phi: REAL);
(* Conversion of a Complex variable from the cartesian to the polar
description. *)
PROCEDURE MultCom(a,b: Complex;VAR z : Complex);
(* MultCom(a,b,c) : c := a * b *)
PROCEDURE DivCom(a,b: Complex;VAR z : Complex);
(* DivCom(a,b,c) : c := a / b *)
PROCEDURE AddCom(a,b: Complex;VAR z : Complex);
(* AddCom(a,b,c) : c := a + b *)
PROCEDURE SubCom(a,b: Complex;VAR z : Complex);
(* SubCom(a,b,c) : c := a - b *)
PROCEDURE NegCom(VAR z : Complex);
(* NegCom(z) : z := -z *)
PROCEDURE ExpCom(VAR z : Complex);
(* ExpCom(z) : z := Exp(z) *)
PROCEDURE SkalCom(VAR z: Complex; r: REAL);
(* SkalCom(c,r: REAL) : c := c * r *)
PROCEDURE RandomCom(VAR z:Complex);
(* generates a random complex number.
not yet implemented! *)
PROCEDURE SetToZero(VAR z:Complex);
(* sets the complex variable a to:
re = 0.0
im = 0.0 *)
END ComplexLib.