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

LONGBCD

Spec.LONGBCD History

Hide minor edits - Show changes to output

2010-05-24 11:55 by benjk -
Changed lines 1-2 from:
[@DEFINITION MODULE LONGBCD;
to:
[@DEFINITION MODULE LONGBCD [RTYPE];
Changed line 12 from:
   BCD = OPAQUE RECORD ("R-Type")
to:
   LONGBCD = OPAQUE RECORD
Changed lines 14-22 from:
   END;

CONST digitCapacity = 30; (
* experimental *)


(* range *)

CONST [TMIN] minValue = -9.99999999999999999999999999E+999;

to:
   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. *)

Changed lines 27-73 from:


(* assignment *)
 
PROCEDURE [:=] assign ( VAR assignTo : LONGBCD; literal : ARRAY OF CHAR );


(* type conversions *)

PROCEDURE [::] toLONGCARD  ( a : LONGBCD ) : LONGCARD;

PROCEDURE [::] toLONGINT ( a : LONGBCD ) : LONGINT;

PROCEDURE [::] toLONGREAL ( a : LONGBCD ) : LONGREAL;


(* monadic arithmetic operations *)

PROCEDURE [ABS] abs ( a : LONGBCD ) : LONGBCD;

PROCEDURE [NEG] neg ( a : LONGBCD ) : LONGBCD;


(* dyadic arithmetic operations *)

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

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

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

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


(* relational operations *)

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

PROCEDURE [<] isLess ( a, b : LONGBCD ) : BOOLEAN;

PROCEDURE [>] isGreater ( a, b : LONGBCD ) : BOOLEAN;


(* scalar conversion primitives *)

CONST digitCapacity = 31; (* total digits *)

to:
(* 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 *)

Changed lines 103-110 from:
(* convert a LONGBCD value to a string in scalar exchange format *)

PROCEDURE [FROM] fromSXF ( VAR b : LONGBCD; s : ARRAY OF CHAR );
(* convert a string in scalar exchange format to a LONGBCD value *)


(* IO operations, bound to READ, WRITE and WRITEF
*)
to:
(* 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
*)
Changed line 116 from:
(* Reads the textual representation of a LONGBCD value in simple format from input stream infile
to:
(* Reads the textual representation of a LONGBCD value from input stream infile
Changed lines 118-128 from:
   - 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 *)

PROCEDURE Write( outfile : File; b : LONGBCD );
(* Writes the textual representation of value b in simple format to output stream outfile *)

PROCEDURE WriteF( outfile : File; fmtStr
: ARRAY OF CHAR;
                 items : CARDINAL; VARIADIC v[items] OF b : LONGBCD );
(* Writes a formatted textual representation of one or more LONGBCD values to output stream outfile. The
  value of parameter items is calculated and inserted automatically. The output format is determined by fmtStr. *)
to:
   - 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
. *)
2010-04-11 11:26 by benjk -
Deleted lines 39-45:
(* conversion primitives *)

PROCEDURE [TO] toSerialized ( value : LONGBCD; VAR serialized : ARRAY OF CHAR );

PROCEDURE [FROM] fromSerialized ( VAR value : LONGBCD; serialized : ARRAY OF CHAR );

Added lines 65-75:


(* scalar conversion primitives *)

CONST digitCapacity = 31; (* total digits *)

PROCEDURE [TO] toSXF ( b : LONGBCD; VAR s : ARRAY OF CHAR );
(* convert a LONGBCD value to a string in scalar exchange format *)

PROCEDURE [FROM] fromSXF ( VAR b : LONGBCD; s : ARRAY OF CHAR );
(* convert a string in scalar exchange format to a LONGBCD value *)
2010-04-10 16:44 by benjk -
Changed lines 15-16 from:
 
to:

CONST digitCapacity = 30; (* experimental *)

Deleted lines 40-41:

CONST [LENGTH] maxDigits = 30; (* experimental *)
2010-04-10 16:06 by benjk -
Changed lines 40-47 from:
PROCEDURE [TO] toASCII (     value     : LONGBCD;
                       VAR isDecimal : BOOLEAN;
                        VAR mantissa  : ARRAY OF CHAR;
                        VAR exponent  : ARRAY OF CHAR );

PROCEDURE [FROM] fromASCII ( isDecimal : BOOLEAN;
                            mantissa  : ARRAY OF CHAR;
                            exponent  : ARRAY OF CHAR ) : LONGBCD
;
to:
CONST [LENGTH] maxDigits = 30; (* experimental *)

PROCEDURE [TO] toSerialized ( value
: LONGBCD; VAR serialized : ARRAY OF CHAR );

PROCEDURE [FROM] fromSerialized ( VAR value : LONGBCD; serialized : ARRAY OF CHAR )
;
2010-04-06 16:53 by benjk -
Deleted lines 15-19:

(* number type *)

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

2010-04-06 07:39 by benjk -
Added lines 41-52:


(* conversion primitives *)

PROCEDURE [TO] toASCII (    value    : LONGBCD;
                        VAR isDecimal : BOOLEAN;
                        VAR mantissa  : ARRAY OF CHAR;
                        VAR exponent  : ARRAY OF CHAR );

PROCEDURE [FROM] fromASCII ( isDecimal : BOOLEAN;
                            mantissa  : ARRAY OF CHAR;
                            exponent  : ARRAY OF CHAR ) : LONGBCD;
2010-04-05 19:20 by benjk -
Deleted lines 47-48:

PROCEDURE [ODD] odd ( a : LONGBCD ) : BOOLEAN;
2010-04-05 12:15 by benjk -
Changed line 12 from:
   BCD = OPAQUE RECORD ("C-Type")
to:
   BCD = OPAQUE RECORD ("R-Type")
Changed line 19 from:
CONST [TYPE] semanticModel = 'R';
to:
CONST [TYPE] semanticModel = 'R'; (* obsolete *)
2010-04-05 12:14 by benjk -
Changed line 12 from:
   BCD = OPAQUE RECORD ['R']
to:
   BCD = OPAQUE RECORD ("C-Type")
2010-04-05 10:40 by benjk -
Changed line 12 from:
   BCD = OPAQUE RECORD
to:
   BCD = OPAQUE RECORD ['R']
2010-04-04 11:48 by benjk -
Deleted lines 30-31:
CONST [.] decimalPointLiterals = TRUE; (* decimal point literals are assignment compatible *)
2010-04-04 09:26 by benjk -
2010-04-04 09:25 by benjk -
Changed lines 5-6 from:
FROM FileIO IMPORT File;
to:

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


(* LONGBCD type *)

Changed lines 12-13 from:
   LONGBCD = OPAQUE RECORD
        value : BITSET [16]; (* 128 bits *)
to:
   BCD = OPAQUE RECORD
        value : ARRAY 16 OF OCTET; (* 128 bits *)
Added lines 16-21:

(* number type *)

CONST [TYPE] semanticModel = 'R';

Changed lines 24-27 from:
PROCEDURE [MIN] minValue : LONGBCD;

PROCEDURE [MAX] maxValue : LONGBCD; 
to:
CONST [TMIN] minValue = -9.99999999999999999999999999E+999;

CONST [TMAX] maxValue = +9.99999999999999999999999999E+999;

Changed lines 31-34 from:
PROCEDURE [.] decimalPointLiterals : BOOLEAN;

PROCEDURE [:=] assign ( literal : ARRAY OF CHAR ) : LONGBCD;

to:
CONST [.] decimalPointLiterals = TRUE; (* decimal point literals are assignment compatible *)

PROCEDURE [:=] assign ( VAR assignTo : LONGBCD; literal : ARRAY OF CHAR );


Changed lines 38-45 from:
PROCEDURE [::] toLONGCARD  (a : BCD ) : LONGCARD;

PROCEDURE [::] toLONGINT ( a : BCD ) : LONGINT;

PROCEDURE [::] toLONGREAL ( a : BCD ) : LONGREAL;

(* unary
arithmetic operations *)
to:
PROCEDURE [::] toLONGCARD  ( a : LONGBCD ) : LONGCARD;

PROCEDURE [::] toLONGINT ( a : LONGBCD ) : LONGINT;

PROCEDURE [::] toLONGREAL ( a : LONGBCD ) : LONGREAL;


(* monadic
arithmetic operations *)
Changed lines 53-54 from:
(* binary arithmetic operations *)
to:

(* dyadic arithmetic operations *)
Added line 64:
Changed lines 67-70 from:
PROCEDURE [=] isEqual ( a, b : BCD ) : BOOLEAN;

PROCEDURE [#] isNotEqual
( a, b : LONGBCD ) : BOOLEAN;
to:
PROCEDURE [=] isEqual ( a, b : LONGBCD ) : BOOLEAN;
Deleted lines 70-71:
PROCEDURE [<=] isLessOrEqual ( a, b : LONGBCD ) : BOOLEAN;
Changed lines 73-108 from:
PROCEDURE [>=] isGreaterOrEqual ( a, b : LONGBCD ) : BOOLEAN;

(* IO operations *)

(* The EBNF for the textual representation of a value of type LONGBCD is equivalent to that of type BCD:

    longBCDValue : unpaddedLongBCDValue | leftPaddedLongBCDValue | rightPaddedLongBCDValue ;
    leftPaddedLongBCDValue : padding+ unPaddedLongBCDValue ;
    rightPaddedLongBCDValue : unPaddedLongBCDValue padding+ ;
    unPaddedLongBCDValue : simpleFormat | otherFormats ;
    otherFormats : sign? fillChar* ( fixedFmtNumeral | engFmtNumeral | expFmtNumeral ) suffix? ;
    simpleFormat : negativeSign? decimalDigit '.' decimalDigit+ exponent ;
    fixedFmtNumeral : integralPart decimalPoint fractionalPart ;
    engFmtNumeral : engIntegralPart decimalPoint fractionalPart engExponent ;
    expFmtNumeral : fixedFmtNumeral exponent ;
    padding : ' ' ;
    sign : ' ' | '+' | '-' ;
    negativeSign : '-' ;
    fillChar : ' ' | '*' | '0' ;
    integralPart : decimalDigit decimalDigit? decimalDigit? ( separator? digitGroup )* ;
    engIntegralPart : ( ( ( decimalDigit separator? )? decimalDigit )? decimalDigit )? decimalDigit ;
    fractionalPart : ( decimalDigit ( decimalDigit ( decimalDigit separator )? )? )* decimalDigit ;
    exponent : 'E' ( '+' | '-' ) decimalDigit decimalDigit+ ;
    engExponent : exponent ;
    decimalPoint : '.' | ',' ;
    separator : ' ' | '.' | ',' ;
    digitGroup : decimalDigit decimalDigit decimalDigit ;
    decimalDigit  : '0' .. '9' ;
    suffix : ''' character* ''' ;

  Static semantics are as follows:

    decimalPoint and separator must never both use the same symbol
    the numeric value represented by engExponent must always be divisible by three. *)

to:

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

Changed lines 81-82 from:
   - the file status is set to any of allRight, outOfRange, wrongFormat, endOfLine, or endOfInput *)
to:
   - the file status is set to any of success, outOfRange, wrongFormat, endOfLine, or endOfInput *)
Changed lines 86-88 from:
PROCEDURE WriteF( outfile : File; fmtStr : ARRAY OF CHAR; items : CARDINAL; VARIADIC v[items] OF b : LONGBCD );
(* Writes a formatted textual representation of one or more LONGBCD values to output stream outfile. The value
 
of parameter items is calculated and inserted automatically. The output format is determined by fmtStr. *)
to:
PROCEDURE WriteF( outfile : File; fmtStr : ARRAY OF CHAR;
                 items : CARDINAL; VARIADIC v[items] OF b : LONGBCD );
(* Writes a formatted textual representation of one or more LONGBCD values to output stream outfile. The
  value
of parameter items is calculated and inserted automatically. The output format is determined by fmtStr. *)