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

IO Module REAL With Multiple Formatting Parameters

DEFINITION MODULE REAL;

(* File based I/O for type REAL *)

FROM FileIO IMPORT File;

// EBNF for textual representation of values of type REAL:
//
// Scientific format :
//   ( '+' | '-' )? decimalDigit '.' digitGroup ( ',' digitGroup )* scaleFactor ;
//
// Engineering format :
//   ( '+' | '-' )? decimalDigit decimalDigit? decimalDigit? ( ',' digitGroup )*
//   '.' digitGroup ( ',' digitGroup )* scaleFactor ;
//
// Ledger format :
//  ( '+' | '-' )? whitespace* decimalDigit decimalDigit? decimalDigit? ( ',' digitGroup )*
//  ( '.' decimalDigits+ )?
//
// Simple format :
//   ( '+' | '-' )? decimalDigit+ ( '.' decimalDigits+ )?
//
// digitGroup :
//   decimalDigit decimalDigit decimalDigit ;
//
// scaleFactor :
//   ( '+' | '-') decimalDigit+ ;
//
// decimalDigit :
//   '0' .. '9' ;


PROCEDURE Read( infile : File; VAR num : REAL );
(* Reads the textual representation of a REAL 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 num
   - the file status is set to any of allRight, outOfRange, wrongFormat, endOfLine, or endOfInput *)

PROCEDURE Write( outfile : File; num : REAL );
(* Writes the textual representation of num in scientific format showing nine places after the
   decimal point to output stream outfile without padding. *)

PROCEDURE WriteF( outfile : File; num : REAL; n : CARDINAL);
(* Writes the textual representation of num in scientific format showing n places after the
   decimal point to output stream outfile without padding. *)

PROCEDURE WriteEng( outfile : File; num : REAL; n, m, exp : CARDINAL );
(* Writes the textual representation of num in engineering format showing n places before and
   m places after the decimal point with exponent exp to output stream outfile without padding.
   Parameters m and exp are rounded to the nearest value of three. *)

PROCEDURE WriteLedger( outfile : File; num : REAL; i, n : CARDINAL );
(* Writes the textual representation of num in ledger format with the sign at position 0, the decimal
   point at position i and showing n places after the decimal point to output stream outfile. *)

PROCEDURE WriteFixed( outfile : File; num : REAL; i, n : CARDINAL );
(* Writes the textual representation of num in simple format with the decimal point at position i
    and showing n places after the decimal point to output stream outfile.

END REAL.