Site Menu Project Specification Implementation Recommendations Reference Needs Updating Work in Progress Wastebasket Wiki Manual |
Type COMPLEXDEFINITION MODULE COMPLEX; (* Complex Numbers *) FROM FileIO IMPORT File; (* required for IO *) (* COMPLEX type *) TYPE COMPLEX = RECORD ("C-Type") re, (* real part *) im : REAL; (* imaginary part *) END; (* monadic arithmetic operations *) PROCEDURE [ABS] abs ( z : COMPLEX ) : COMPLEX; PROCEDURE [NEG] neg ( z : COMPLEX ) : COMPLEX; (* dyadic arithmetic operations *) PROCEDURE [+] add ( z1, z2 : COMPLEX ) : COMPLEX; PROCEDURE [-] sub ( z1, z2 : COMPLEX ) : COMPLEX; PROCEDURE [*] multiply ( z1, z2 : COMPLEX ) : COMPLEX; PROCEDURE [/] divide ( z1, z2 : COMPLEX ) : COMPLEX; (* relational operations *) PROCEDURE [=] isEqual ( z1, z2 : COMPLEX ) : BOOLEAN; (* IO operations, bound to READ, WRITE and WRITEF *) PROCEDURE Read( infile : File; VAR z : COMPLEX ); (* Reads the textual representation of a COMPLEX value in simple format from input stream infile - any leading whitespace is skipped - any remaining characters that are part of the numeral being read are removed from infile - the numeric value of the numeral string read is assigned to the variable passed in for z - the file status is set to any of success, outOfRange, wrongFormat, endOfLine, or endOfInput *) PROCEDURE Write( outfile : File; z : COMPLEX ); (* Writes the textual representation of COMPLEX value z in simple format to output stream outfile *) PROCEDURE WriteF( outfile : File; fmtStr : ARRAY OF CHAR; items : CARDINAL; VARIADIC v[items] OF z : COMPLEX ); (* Writes a formatted textual representation of one or more COMPLEX values to output stream outfile. The value of parameter items is calculated and inserted automatically. The output format is determined by fmtStr. *) END COMPLEX. |