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

LONGCOMPLEX

Spec.LONGCOMPLEX History

Hide minor edits - Show changes to output

2010-05-24 13:07 by benjk -
Changed lines 1-2 from:
[@DEFINITION MODULE LONGCOMPLEX;
to:
[@DEFINITION MODULE LONGCOMPLEX [CTYPE];
Changed line 12 from:
   LONGCOMPLEX = RECORD ("C-Type")
to:
   LONGCOMPLEX = RECORD
2010-05-24 11:56 by benjk -
Changed lines 1-42 from:
[@DEFINITION MODULE LONGCOMPLEX;

(* Double Precision Complex Numbers *) 

TYPE

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

(* constructor and accessors *)

PROCEDURE ( self : LONGCOMPLEX ) Cmplx( re, im : LONGREAL ) : LONGCOMPLEX;

PROCEDURE ( self : LONGCOMPLEX ) Re( a : LONGCOMPLEX ) : LONGREAL;

PROCEDURE ( self : LONGCOMPLEX ) Im( a : LONGCOMPLEX ) : LONGREAL;

(* unary arithmetic operations *)

PROCEDURE [ABS] ( self : LONGCOMPLEX ) abs ( a : LONGCOMPLEX ) : LONGCOMPLEX; 

PROCEDURE [NEG] ( self : LONGCOMPLEX ) neg ( a : LONGCOMPLEX ) : LONGCOMPLEX; 

(* binary arithmetic operations *) 

PROCEDURE [+] ( self : LONGCOMPLEX ) add ( a, b : LONGCOMPLEX ) : LONGCOMPLEX; 

PROCEDURE [-] ( self : LONGCOMPLEX ) sub ( a, b : LONGCOMPLEX ) : LONGCOMPLEX; 

PROCEDURE [*] ( self : LONGCOMPLEX ) multiply ( a, b : LONGCOMPLEX ) : LONGCOMPLEX; 

PROCEDURE [/] ( self : LONGCOMPLEX ) divide ( a, b : LONGCOMPLEX ) : LONGCOMPLEX; 

(* relational operations *)

PROCEDURE [=] ( self : LONGCOMPLEX ) isEqual ( a, b : LONGCOMPLEX ) : BOOLEAN; 

PROCEDURE [#] ( self : LONGCOMPLEX ) isNotEqual ( a, b : LONGCOMPLEX ) : BOOLEAN;

(* I/O operations might follow here *)
to:
[@DEFINITION MODULE LONGCOMPLEX;

(* Double Precision Complex Numbers *)


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


(* LONGCOMPLEX type *)

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


(* C-Type bindings to operators, pervasives and primitives: *)


(* Monadic arithmetic operations *)

PROCEDURE [ABS] abs ( z : LONGCOMPLEX ) : LONGCOMPLEX;
(* Returns the absolute value of LONGCOMPLEX value z.
  This function is bound to pervasive function ABS for type LONGCOMPLEX. *)

PROCEDURE [NEG] neg ( z : LONGCOMPLEX ) : LONGCOMPLEX;
(* Returns the sign reversed value of LONGCOMPLEX value z.
  This function is bound to the unary minus operator for type LONGCOMPLEX. *)


(* Dyadic arithmetic operations *)

PROCEDURE [+] add ( z1, z2 : LONGCOMPLEX ) : LONGCOMPLEX;
(* Adds LONGCOMPLEX values z1 and z2 and returns the result.
  This function is bound to the + operator for type LONGCOMPLEX. *)

PROCEDURE [-] sub ( z1, z2 : LONGCOMPLEX ) : LONGCOMPLEX;
(* Subtracts LONGCOMPLEX value z2 from z1 and returns the result.
  This function is bound to the - operator for type LONGCOMPLEX. *)

PROCEDURE [*] multiply ( z1, z2 : LONGCOMPLEX ) : LONGCOMPLEX;
(* Multiplies LONGCOMPLEX values z1 and z2 and returns the result.
  This function it bound to the * operator for type LONGCOMPLEX. *)

PROCEDURE [/] divide ( z1, z2 : LONGCOMPLEX ) : LONGCOMPLEX;
(* Divives LONGCOMPLEX value z1 by z2 and returns the result.
  This function is bound to the / operator for type LONGCOMPLEX. *)


(* Relational operations *)

PROCEDURE [=] isEqual ( z1, z2 : LONGCOMPLEX ) : BOOLEAN;
(* Returns TRUE if LONGCOMPLEX values z1 and z2 are equal, otherwise FALSE.
  This function is bound to operators = and # for type LONGCOMPLEX. *)


(* IO operations *)

PROCEDURE Read( infile : File; VAR z : LONGCOMPLEX );
(* Reads the textual representation of a LONGCOMPLEX value from 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. This procedure
    is substituted for invocations of READ with a LONGCOMPLEX argument. *)

PROCEDURE Write( outfile : File; CONST z : LONGCOMPLEX );
(* Writes the textual representation of value z to stream outfile. This pro-
  cedure is substituted for invocations of WRITE with a LONGCOMPLEX argument.*)

PROCEDURE WriteF ( outfile      : File;
                  CONST fmtStr : ARRAY OF CHAR;
                  items        : VARIADIC OF CONST LONGCOMPLEX );
(* Writes a formatted textual representation of one or more LONGCOMPLEX values
  to output stream outfile. The output format is determined by fmtStr. This
  procedure is substituted for invocations of WRITEF with one or more
  LONGCOMPLEX arguments. *)