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

Type LONGCOMPLEX

WiP.TypeLONGCOMPLEX History

Hide minor edits - Show changes to output

2010-04-09 19:03 by benjk -
Changed line 11 from:
   LONGCOMPLEX = OPAQUE RECORD ("C-Type")
to:
   LONGCOMPLEX = RECORD ("C-Type")
Deleted lines 14-36:


(* 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;
2010-04-08 16:04 by benjk -
Changed lines 17-21 from:
(* constructor and accessors *)

PROCEDURE Cmplx ( re, im : LONGREAL ) : LONGCOMPLEX;
(* constructs a complex number from an ordered pair
*)
to:
(* unbound accessors for convenience *)
Added lines 24-32:


(* 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 *)
2010-04-06 17:06 by benjk -
Deleted lines 16-20:
(* number type *)

CONST [TYPE] semanticModel = 'C'; (* obsolete *)

Changed line 19 from:
PROCEDURE Cmplx ( real, imag : LONGREAL ) : LONGCOMPLEX;
to:
PROCEDURE Cmplx ( re, im : LONGREAL ) : LONGCOMPLEX;
Changed lines 31-33 from:
CONST [{}] allowValueConstructors = TRUE; (* either this or ... *)

CONST [:=] allowValueConstructors = TRUE; (* but this needs more checks *)
to:
CONST [{}] allowValueConstructors = TRUE;
2010-04-05 12:19 by benjk -
Changed lines 11-12 from:
   LONGCOMPLEX = OPAQUE RECORD
        re : LONGREAL; (* real part *)
to:
   LONGCOMPLEX = OPAQUE RECORD ("C-Type")
       re,           (* real part *)
Changed line 19 from:
CONST [TYPE] semanticModel = 'C';
to:
CONST [TYPE] semanticModel = 'C'; (* obsolete *)
2010-04-04 10:16 by benjk -
Changed line 27 from:
PROCEDURE Re ( z : COMPLEX ) : LONGREAL;
to:
PROCEDURE Re ( z : LONGCOMPLEX ) : LONGREAL;
Changed line 30 from:
PROCEDURE Im ( z : COMPLEX ) : LONGREAL;
to:
PROCEDURE Im ( z : LONGCOMPLEX ) : LONGREAL;
2010-04-04 10:15 by benjk -
Changed lines 33-65 from:
[@DEFINITION MODULE COMPLEX;

(* Complex Numbers *)

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


(* COMPLEX type *)

TYPE
    COMPLEX = OPAQUE RECORD
        re : REAL; (* real part *)
        im : REAL; (* imaginary part *)
    END;


(* number type *)

CONST [TYPE] semanticModel = 'C';


(* constructor and accessors *)

PROCEDURE Cmplx ( real, imag : REAL ) : COMPLEX;
(* constructs a complex number from an ordered pair *)

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

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

to:
Deleted lines 39-79:

(* 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.@]
2010-04-04 10:02 by benjk -
Added lines 33-112:
[@DEFINITION MODULE COMPLEX;

(* Complex Numbers *)

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


(* COMPLEX type *)

TYPE
    COMPLEX = OPAQUE RECORD
        re : REAL; (* real part *)
        im : REAL; (* imaginary part *)
    END;


(* number type *)

CONST [TYPE] semanticModel = 'C';


(* constructor and accessors *)

PROCEDURE Cmplx ( real, imag : REAL ) : COMPLEX;
(* constructs a complex number from an ordered pair *)

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

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


(* literal assignment *)

CONST [{}] allowValueConstructors = TRUE; (* either this or ... *)

CONST [:=] allowValueConstructors = TRUE; (* but this needs more checks *)


(* 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.@]
2010-04-04 09:33 by benjk -
Changed lines 3-6 from:
(* Complex Numbers *)

FROM FileIO IMPORT
File;
to:
(* Double Precision Complex Numbers *)

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


(* LONGCOMPLEX type *)

Changed lines 12-13 from:
       re : LONGREAL;
       im : LONGREAL;
to:
       re : LONGREAL; (* real part *)
        im : LONGREAL; (* imaginary part *)
Changed lines 24-27 from:
PROCEDURE Cmplx ( real, imag : REAL ) : LONGCOMPLEX;
(* constructs a complex from an ordered pair *)

PROCEDURE Re ( z : LONGCOMPLEX ) : LONGREAL;
to:
PROCEDURE Cmplx ( real, imag : LONGREAL ) : LONGCOMPLEX;
(* constructs a complex number from an ordered pair *)

PROCEDURE Re ( z : COMPLEX ) : LONGREAL;
Changed line 30 from:
PROCEDURE Im ( z : LONGCOMPLEX ) : LONGREAL;
to:
PROCEDURE Im ( z : COMPLEX ) : LONGREAL;
Changed lines 56-61 from:
PROCEDURE [#] isNotEqual ( z1, z2 : LONGCOMPLEX ) : BOOLEAN;


(* IO operations *)

PROCEDURE (* [READ] *)
Read( infile : File; VAR z : LONGCOMPLEX );
to:

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

PROCEDURE
Read( infile : File; VAR z : LONGCOMPLEX );
Changed lines 64-87 from:
   - the file status is set to any of allRight, outOfRange, wrongFormat, endOfLine, or endOfInput *)

PROCEDURE (* [WRITE] *) Write( outfile : File; z : LONGCOMPLEX );
(* Writes the textual representation of z in scientific format showing nine places after the
 
  decimal point to output stream outfile without padding. *)

PROCEDURE (* [WRITEF] *) WriteF( outfile : File; z : LONGCOMPLEX; n : CARDINAL);
(* Writes the textual representation of z in scientific format showing n places after the
  decimal point to output stream outfile without padding. *)

PROCEDURE (* [WRITEF] *) WriteFixed(
outfile : File; z : LONGCOMPLEX; i, n : CARDINAL );
(* Writes the textual representation of z in simple format with the decimal point at position i
    and showing n places after the decimal point to output stream outfile.

(* unbound IO operations *)

PROCEDURE WriteEng( outfile : File; z : LONGCOMPLEX; n, m, exp : CARDINAL );
(* Writes the textual representation of z in engineering format showing n places before and
  m places after the decimal point with exponent exp to output stream outfile without padding.
  Parameters m and exp are rounded to the nearest value of three. *)

PROCEDURE WriteLedger( outfile : File; z : LONGCOMPLEX; i, n : CARDINAL );
(* Writes the textual representation of z in ledger format with the sign at position 0, the decimal
  point at position i and showing n places after the decimal point to output stream outfile
. *)
to:
   - 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.
*)
2010-04-04 09:30 by benjk -
Added lines 13-18:

(* number type *)

CONST [TYPE] semanticModel = 'C';

Changed lines 31-32 from:
(* unary arithmetic operations *)
to:
(* monadic arithmetic operations *)
Changed line 38 from:
(* binary arithmetic operations *)
to:
(* dyadic arithmetic operations *)
2010-01-17 12:48 by benjk -
Added lines 1-82:
[@DEFINITION MODULE LONGCOMPLEX;

(* Complex Numbers *)

FROM FileIO IMPORT File;

TYPE
    LONGCOMPLEX = OPAQUE RECORD
        re : LONGREAL;
        im : LONGREAL;
    END;

(* constructor and accessors *)

PROCEDURE Cmplx ( real, imag : REAL ) : LONGCOMPLEX;
(* constructs a complex from an ordered pair *)

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 *)


(* unary arithmetic operations *)

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

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


(* binary 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;

PROCEDURE [#] isNotEqual ( z1, z2 : LONGCOMPLEX ) : BOOLEAN;


(* IO operations *)

PROCEDURE (* [READ] *) 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 allRight, outOfRange, wrongFormat, endOfLine, or endOfInput *)

PROCEDURE (* [WRITE] *) Write( outfile : File; z : LONGCOMPLEX );
(* Writes the textual representation of z in scientific format showing nine places after the
  decimal point to output stream outfile without padding. *)

PROCEDURE (* [WRITEF] *) WriteF( outfile : File; z : LONGCOMPLEX; n : CARDINAL);
(* Writes the textual representation of z in scientific format showing n places after the
  decimal point to output stream outfile without padding. *)

PROCEDURE (* [WRITEF] *) WriteFixed( outfile : File; z : LONGCOMPLEX; i, n : CARDINAL );
(* Writes the textual representation of z in simple format with the decimal point at position i
    and showing n places after the decimal point to output stream outfile.

(* unbound IO operations *)

PROCEDURE WriteEng( outfile : File; z : LONGCOMPLEX; n, m, exp : CARDINAL );
(* Writes the textual representation of z in engineering format showing n places before and
  m places after the decimal point with exponent exp to output stream outfile without padding.
  Parameters m and exp are rounded to the nearest value of three. *)

PROCEDURE WriteLedger( outfile : File; z : LONGCOMPLEX; i, n : CARDINAL );
(* Writes the textual representation of z in ledger format with the sign at position 0, the decimal
  point at position i and showing n places after the decimal point to output stream outfile. *)

END LONGCOMPLEX.@]