Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

OPAQUE Type LONGCOMPLEX

DEFINITION MODULE LONGCOMPLEX;

(* Double Precision Complex Numbers *) 

FROM FileIO IMPORT File; (* required for IO *)


(* LONGCOMPLEX type *)

TYPE
    LONGCOMPLEX = OPAQUE RECORD ("C-Type")
        re,            (* real part *)
        im : LONGREAL; (* imaginary part *)
    END;


(* unbound accessors for convenience *)

PROCEDURE Re ( z : LONGCOMPLEX ) : LONGREAL;
(* returns the real part of a complex number *)

PROCEDURE Im ( z : LONGCOMPLEX ) : LONGREAL;
(* returns the imaginary part of a complex number *)


(* bound accessor and mutator *)

PROCEDURE [.] component ( n : CARDINAL; z : LONGCOMPLEX ) : LONGREAL;
(* Returns the value of the n-th component of complex number z *)

PROCEDURE [!] setComponent ( n : CARDINAL; VAR z : LONGCOMPLEX; r : LONGREAL );
(* Overwrites the value of the n-th component of complex number z with r *)


(* literal assignment *)

CONST [{}] allowValueConstructors = TRUE;


(* monadic arithmetic operations *) 

PROCEDURE [ABS] abs ( z : LONGCOMPLEX ) : LONGCOMPLEX; 

PROCEDURE [NEG] neg ( z : LONGCOMPLEX ) : LONGCOMPLEX; 


(* dyadic arithmetic operations *) 

PROCEDURE [+] add ( z1, z2 : LONGCOMPLEX ) : LONGCOMPLEX; 

PROCEDURE [-] sub ( z1, z2 : LONGCOMPLEX ) : LONGCOMPLEX; 

PROCEDURE [*] multiply ( z1, z2 : LONGCOMPLEX ) : LONGCOMPLEX; 

PROCEDURE [/] divide ( z1, z2 : LONGCOMPLEX ) : LONGCOMPLEX; 


(* relational operations *) 

PROCEDURE [=] isEqual ( z1, z2 : LONGCOMPLEX ) : BOOLEAN; 


(* IO operations, bound to READ, WRITE and WRITEF *)

PROCEDURE Read( infile : File; VAR z : LONGCOMPLEX );
(* Reads the textual representation of a LONGCOMPLEX 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 : LONGCOMPLEX );
(* Writes the textual representation of LONGCOMPLEX value z in simple format to output stream outfile *)

PROCEDURE WriteF( outfile : File; fmtStr : ARRAY OF CHAR;
                  items : CARDINAL; VARIADIC v[items] OF z : LONGCOMPLEX );
(* Writes a formatted textual representation of one or more LONGCOMPLEX values to output stream outfile. The
   value of parameter items is calculated and inserted automatically. The output format is determined by fmtStr. *)

END LONGCOMPLEX.