Modula-2 Reloaded ⋄ IO Module LONGREAL With Multiple Formatting Parameters

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 LONGREAL With Multiple Formatting Parameters

DEFINITION MODULE LONGREAL;

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

FROM FileIO IMPORT File;

// EBNF for textual representation of values of type LONGREAL:
//
// 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 : LONGREAL );
(* Reads the textual representation of a LONGREAL 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 : LONGREAL );
(* 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 : LONGREAL; 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 : LONGREAL; 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 : LONGREAL; 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 : LONGREAL; 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 LONGREAL.