Site Menu Project Specification Implementation Recommendations Reference Needs Updating Work in Progress Wastebasket Wiki Manual |
Type LONGNATDEFINITION MODULE LONGNAT; (* Long Natural Numbers *) FROM FileIO IMPORT File; (* required for IO *) (* LONGNAT type *) TYPE LONGNAT = OPAQUE RECORD value : LONGINT; (* subset of long integer *) END; (* number system *) CONST [N] isWholeNumberType = TRUE; (* range *) CONST [TMIN] minValue = 0; CONST [TMAX] maxValue = TMAX(LONGINT); (* assignment *) CONST [.] decimalPointLiterals = FALSE; PROCEDURE [:=] assign ( VAR assignTo : LONGNAT; literal : ARRAY OF CHAR ); (* type conversions *) PROCEDURE [::] toCARD ( a : LONGNAT ) : CARDINAL; PROCEDURE [::] toINT ( a : LONGNAT ) : INTEGER; PROCEDURE [::] toREAL ( a : LONGNAT ) : REAL; (* unary arithmetic operations *) PROCEDURE [ABS] abs ( a : LONGNAT ) : LONGNAT; PROCEDURE [ODD] odd ( a : LONGNAT ) : BOOLEAN; (* binary arithmetic operations *) PROCEDURE [+] add ( a, b : LONGNAT ) : LONGNAT; PROCEDURE [-] sub ( a, b : LONGNAT ) : LONGNAT; PROCEDURE [*] multiply ( a, b : LONGNAT ) : LONGNAT; PROCEDURE [DIV] divide ( a, b : LONGNAT ) : LONGNAT; (* relational operations *) PROCEDURE [=] isEqual ( a, b : LONGNAT ) : BOOLEAN; PROCEDURE [<] isLess ( a, b : LONGNAT ) : BOOLEAN; PROCEDURE [>] isGreater ( a, b : LONGNAT ) : BOOLEAN; (* IO operations, bound to READ, WRITE and WRITEF *) PROCEDURE Read( infile : File; VAR n : LONGNAT ); (* Reads the textual representation of a LONGNAT 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 n - the file status is set to any of success, outOfRange, wrongFormat, endOfLine, or endOfInput *) PROCEDURE Write( outfile : File; n : LONGNAT ); (* Writes the textual representation of value n in simple format to output stream outfile *) PROCEDURE WriteF( outfile : File; fmtStr : ARRAY OF CHAR; items : CARDINAL; VARIADIC v[items] OF n : LONGNAT ); (* Writes a formatted textual representation of one or more LONGNAT values to output stream outfile. The value of parameter items is calculated and inserted automatically. The output format is determined by fmtStr. *) END LONGNAT. |