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

Whole Number Formatting

Unsigned Whole Numbers

Digit Group format

unsignedWholeNumeral :
  decimalDigit decimalDigit? ( ',' digitGroup )* ;
digitGroup :
  decimalDigit decimalDigit decimalDigit ;
decimalDigit :
  '0' .. '9' ;

Example: 1,234,567,890

Formatting parameters:

  • none

Simple format

simpleUnsignedNumeral :
  decimalDigit+ ;
decimalDigit :
  '0' .. '9' ;

Example: 1234567890

Formatting parameters

  • none

Base-16 format

base16Numeral :
  sedecimalDigit+ ;
sedecimalDigit :
  '0' .. '9' | 'A' .. 'F' ;

Example: 07123ABCD

Signed Whole Numbers

Digit Group format

signedWholeNumeral :
  ( '+' | '-' )? decimalDigit decimalDigit? ( ',' digitGroup )* ;
digitGroup :
  decimalDigit decimalDigit decimalDigit ;
decimalDigit :
  '0' .. '9' ;

Example: -1,234,567,890

Formatting parameters:

  • none

Simple format

simpleUnsignedNumeral :
  ( '+' | '-' )? decimalDigit+ ;
decimalDigit :
  '0' .. '9' ;

Example: 1234567890

Formatting parameters

  • none

Base-16 format

base16Numeral :
  sedecimalDigit+ ;
sedecimalDigit :
  '0' .. '9' | 'A' .. 'F' ;

Example: 0DEADBEEF

IO Procedures for Whole Number types

The standard IO library shall provide the following output procedures for every whole number type that is provided by the language core or by the standard library. It shall be recommended that user libraries implementing whole number types also provide these procedures.

PROCEDURE Write( f : File; n : <WholeNumberType> );

shall produce output in digit group format without padding.

PROCEDURE WriteF( f : File; n : <WholeNumberType>; w : CARDINAL );

shall produce output in digit group format right centered into a field of width n.

PROCEDURE WriteBase16( f : File; n : <WholeNumberType> );

shall produce output in base-16 format without padding.

PROCEDURE WriteFixed( f : File; n : <WholeNumberType> );

shall produce output in simple format without padding.

Mapping of WRITE and WRITEF macros

The compiler shall expand the WRITE and WRITEF macros when invoked with a whole number argument as follows:

WRITE( file, wholenum ); shall expand to: TypeOf(wholenum).Write( file, wholenum );

WRITEF( file, wholenum, n ); shall expand to: TypeOf(wholenum).WriteF( file, wholenum, n );

whereby TypeOf(wholenum) is to be replaced by the name of the whole number type.

Affected Types

  • pervasive type CARDINAL
  • pervasive type LONGCARD
  • standard library type INTEGER
  • standard library type LONGINT