Site Menu Project Specification Implementation Recommendations Reference Needs Updating Work in Progress Wastebasket Wiki Manual |
LONGBCDDEFINITION MODULE LONGBCD [RTYPE]; (* Double Precision Binary Coded Decimals *) FROM FileIO IMPORT File; (* required for IO *) (* LONGBCD type *) TYPE LONGBCD = OPAQUE RECORD value : ARRAY 16 OF OCTET; (* 128 bits *) END; (* LONGBCD *) (* R-Type bindings to operators, pervasives and primitives: *) (* Range *) CONST [TMIN] minValue = -9.99999999999999999999999999E+999; (* Smallest value of type LONGBCD. This value is bound to TMIN for type LONGBCD. *) CONST [TMAX] maxValue = +9.99999999999999999999999999E+999; (* Largest value of type LONGBCD. This value is bound to TMAX for type LONGBCD. *) (* Literal assignment *) PROCEDURE [:=] assign ( VAR assignTo : LONGBCD; literal : ARRAY OF CHAR ); (* Converts string literal to a LONGBCD value and assigns it to assignTo. This procedure is bound to the := operator for literal assignment. *) (* Type conversions *) PROCEDURE [::] toCARD ( a : LONGBCD ) : CARDINAL; (* Converts LONGBCD value a to a CARDINAL value and returns it. This function is bound to the :: operator for LONGBCD to CARDINAL conversion. *) PROCEDURE [::] toINT ( a : LONGBCD ) : INTEGER; (* Converts LONGBCD value a to an INTEGER value and returns it. This function is bound to the :: operator for LONGBCD to INTEGER conversion. *) PROCEDURE [::] toREAL ( a : LONGBCD ) : REAL; (* Converts LONGBCD value a to a REAL value and returns it. This function is bound to the :: operator for LONGBCD to REAL conversion. *) (* Monadic arithmetic operations *) PROCEDURE [ABS] abs ( a : LONGBCD ) : LONGBCD; (* Returns the absolute value of LONGBCD value a. This function is bound to pervasive function ABS for type LONGBCD. *) PROCEDURE [NEG] neg ( a : LONGBCD ) : LONGBCD; (* Returns the sign reversed value of LONGBCD value a. This function is bound to the unary minus operator for type LONGBCD. *) (* Dyadic arithmetic operations *) PROCEDURE [+] add ( a, b : LONGBCD ) : LONGBCD; (* Adds LONGBCD values a and b and returns the result. This function is bound to the + operator for type LONGBCD. *) PROCEDURE [-] sub ( a, b : LONGBCD ) : LONGBCD; (* Subtracts LONGBCD value b from a and returns the result. This function is bound to the - operator for type LONGBCD. *) PROCEDURE [*] multiply ( a, b : LONGBCD ) : LONGBCD; (* Multiplies LONGBCD values a and b and returns the result. This function it bound to the * operator for type LONGBCD. *) PROCEDURE [/] divide ( a, b : LONGBCD ) : LONGBCD; (* Divives LONGBCD value a by b and returns the result. This function is bound to the / operator for type LONGBCD. *) (* Relational operations *) PROCEDURE [=] isEqual ( a, b : LONGBCD ) : BOOLEAN; (* Returns TRUE if LONGBCD values a and b are equal, otherwise FALSE. This function is bound to operators = and # for type LONGBCD. *) PROCEDURE [<] isLess ( a, b : LONGBCD ) : BOOLEAN; (* Returns TRUE if LONGBCD value a is less than b, otherwise FASLE. This function is bound to operators < and >= for type LONGBCD. *) PROCEDURE [>] isGreater ( a, b : LONGBCD ) : BOOLEAN; (* Returns TRUE if LONGBCD value a is greater than b, otherwise FALSE. This function is bound to operators > and <= for type LONGBCD. *) (* Scalar conversion primitives *) CONST digitCapacity = 30; (* maximum digits *) PROCEDURE [TO] toSXF ( b : LONGBCD; VAR s : ARRAY OF CHAR ); (* Converts a LONGBCD value to a string in scalar exchange format. This procedure is used to synthesise conversions to other scalar types when no direct conversion path exists. *) PROCEDURE [FROM] fromSXF ( VAR b : LONGBCD; CONST s : ARRAY OF CHAR ); (* Converts a string in scalar exchange format to a LONGBCD value. This procedure is used to synthesise conversions from other scalar types when no direct conversion path exists. *) (* IO operations *) PROCEDURE Read( infile : File; VAR b : LONGBCD ); (* Reads the textual representation of a LONGBCD value 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 b - the file status is set to any of: success, outOfRange, wrongFormat, endOfLine, or endOfInput. This procedure is substituted for invocations of READ with a LONGBCD argument. *) PROCEDURE Write( outfile : File; CONST b : LONGBCD ); (* Writes the textual representation of value b to output stream outfile. This procedure is substituted for invocations of WRITE with a LONGBCD argument.*) PROCEDURE WriteF ( outfile : File; CONST fmtStr : ARRAY OF CHAR; items : VARIADIC OF CONST LONGBCD ); (* Writes a formatted textual representation of one or more LONGBCD values to output stream outfile. The output format is determined by fmtStr. This procedure is substituted for invocations of WRITEF with one or more LONGBCD arguments. *) END LONGBCD. |