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

Real Number Formatting

WiP.RealNumberFormatting History

Hide minor edits - Show changes to output

2010-01-14 19:30 by benjk -
2010-01-14 17:53 by benjk -
Added lines 110-117:


!!!Affected Types
* pervasive type @@REAL@@
* pervasive type @@LONGREAL@@
* standard library type @@BCD@@
* standard library type @@LONGBCD@@

2010-01-14 17:50 by benjk -
Added lines 108-109:

whereby ''@@`TypeOf(realnum)@@''  is to be replaced by the name of the real number type.
2010-01-14 17:32 by benjk -
Added line 20:
Added line 43:
Added line 74:
2010-01-14 17:31 by benjk -
Added line 95:
2010-01-14 17:28 by benjk -
Deleted line 73:
Deleted line 96:
Added lines 102-103:

[@WRITEF( file, realnum, i, n );@]  shall expand to:  ''@@`TypeOf(realnum)@@''[@.WriteFixed( file, realnum, i, n );@]
2010-01-14 17:26 by benjk -
Changed lines 101-103 from:
[@WRITE( file, realnum );@]  shall expand to:  `''@@TypeOf(realnum)@@''[@.Write( file, realnum );@]

[@WRITEF( file, realnum, n );@]  shall expand to:  `''@@TypeOf(realnum)@@''[@.WriteF( file, realnum, n );@]
to:
[@WRITE( file, realnum );@]  shall expand to:  ''@@`TypeOf(realnum)@@''[@.Write( file, realnum );@]

[@WRITEF( file, realnum, n );@]  shall expand to:  ''@@`TypeOf(realnum)@@''[@.WriteF( file, realnum, n );@]
2010-01-14 17:26 by benjk -
Changed lines 75-76 from:
The standard IO library shall provide the following output procedures for every real number type that is provided by the language core or by the standard library.
to:
The standard IO library shall provide the following output procedures for every real number type that is provided by the language core or by the standard library. It shall be recommended that user libraries implementing real number types also provide these procedures.
Added lines 96-103:

!!!Mapping of WRITE and WRITEF macros

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

[@WRITE( file, realnum );@]  shall expand to:  `''@@TypeOf(realnum)@@''[@.Write( file, realnum );@]

[@WRITEF( file, realnum, n );@]  shall expand to:  `''@@TypeOf(realnum)@@''[@.WriteF( file, realnum, n );@]
2010-01-14 17:15 by benjk -
Changed line 75 from:
The following output procedures shall be provided for every real number type, whether pervasive or library supplied.
to:
The standard IO library shall provide the following output procedures for every real number type that is provided by the language core or by the standard library.
2010-01-14 17:13 by benjk -
Added lines 74-75:

The following output procedures shall be provided for every real number type, whether pervasive or library supplied.
2010-01-14 17:09 by benjk -
Changed lines 85-86 from:
shall produce output in engineering format with n places before, m places after the decimal point and exponent exp.
parameters m and exp shall be rounded to the nearest multiple of three.
to:
shall produce output in engineering format with n places before, m places after the decimal point and exponent exp, whereby parameters m and exp shall be rounded to the nearest multiple of three.
2010-01-14 17:08 by benjk -
Added line 86:
parameters m and exp shall be rounded to the nearest multiple of three.
2010-01-14 17:05 by benjk -
2010-01-14 16:58 by benjk -
Changed line 45 from:
  ( '+' | '-' )? decimalDigit decimalDigit? decimalDigit? ( ',' digitGroup )*
to:
  ( '+' | '-' )? whitespace* decimalDigit decimalDigit? decimalDigit? ( ',' digitGroup )*
2010-01-14 16:54 by benjk -
Added line 76:
Added line 80:
Added line 84:
Added line 88:
Added line 92:
2010-01-14 16:54 by benjk -
Changed line 78 from:
[@PROCEDURE WriteF( f : File; r : <RealType>; n : CARDINAL );
to:
[@PROCEDURE WriteF( f : File; r : <RealType>; n : CARDINAL );@]
Changed line 81 from:
[@PROCEDURE WriteEng( f : File; r : <RealType>; n, m, exp : CARDINAL );
to:
[@PROCEDURE WriteEng( f : File; r : <RealType>; n, m, exp : CARDINAL );@]
Changed line 84 from:
[@PROCEDURE WriteLedger( f : File; r : <RealType>; i, n : CARDINAL );
to:
[@PROCEDURE WriteLedger( f : File; r : <RealType>; i, n : CARDINAL );@]
Changed line 87 from:
[@PROCEDURE WriteFixed( f : File; r : <RealType>; i, n : CARDINAL );
to:
[@PROCEDURE WriteFixed( f : File; r : <RealType>; i, n : CARDINAL );@]
2010-01-14 16:53 by benjk -
Added lines 73-88:
!!!IO Procedures for Real Number types

[@PROCEDURE Write( f : File; r : <RealType> );@]
shall produce output in scientific format with 9 places after the decimal point.

[@PROCEDURE WriteF( f : File; r : <RealType>; n : CARDINAL );
shall produce output in scientific format with n places after the decimal point.

[@PROCEDURE WriteEng( f : File; r : <RealType>; n, m, exp : CARDINAL );
shall produce output in engineering format with n places before, m places after the decimal point and exponent exp.

[@PROCEDURE WriteLedger( f : File; r : <RealType>; i, n : CARDINAL );
shall produce output in ledger format with the decimal point at index i and n places after the decimal point.

[@PROCEDURE WriteFixed( f : File; r : <RealType>; i, n : CARDINAL );
shall produce output in simple format with the decimal point at index i and n places after the decimal point.
2010-01-14 16:31 by benjk -
Changed lines 18-19 from:
* places after decimal point
to:
* number of places after decimal point
Changed lines 38-39 from:
* places before decimal point
* places after decimal point
to:
* number of places before decimal point
* number of places after decimal point
Changed lines 57-58 from:
* places after decimal point
to:
* number of places after decimal point
Changed line 71 from:
* places after decimal point
to:
* number of places after decimal point
2010-01-14 16:30 by benjk -
Changed lines 15-16 from:
Example: 1.234,567,890+E00
to:
Example: 1.234,567,890E+00

Formatting parameters:
* places after decimal point

Added lines 37-41:
Formatting parameters:
* places before decimal point
* places after decimal point
* exponent

Added lines 55-58:
Formatting parameters:
* index of decimal point in output field
* places after decimal point

Added lines 68-72:

Formatting parameters:
* index of decimal point in output field
* places after decimal point

2010-01-14 16:17 by benjk -
Changed line 49 from:
ledgerReal :
to:
simpleReal :
2010-01-14 16:16 by benjk -
Changed lines 32-33 from:
Example: 1,234.456,789E+03
to:
Example: 1,234.567,890E+03
Changed lines 45-55 from:
Example: 1,234,456.00
to:
Examples: 1,234,567.00 or 1,234,567

!!!Simple format, defined by the following EBNF:
[@
ledgerReal :
  ( '+' | '-' )? decimalDigit+ ( '.' decimalDigits+ )?
decimalDigit :
  '0' .. '9' ;
@]

Examples: 123456.7890 or 123456
2010-01-14 16:09 by benjk -
Changed line 21 from:
  '.' digitGroup ( ',' digitGroup )* engScaleFactor ;
to:
  '.' digitGroup ( ',' digitGroup )* scaleFactor ;
Changed lines 24-25 from:
engScaleFactor :
  ( '+' | '-' ) digitGroup ;
to:
scaleFactor :
  ( '+' | '-') decimalDigit+ ;
Changed lines 30-32 from:
The numeric value of @@engScaleFactor@@ must be divisible by three.

Example: 1,234.456,789E+000
to:
The numeric value of @@scaleFactor@@ must be divisible by three.

Example: 1,234.456,789E+03
2010-01-14 16:07 by benjk -
Added lines 29-30:

The numeric value of @@engScaleFactor@@ must be divisible by three.
2010-01-14 16:02 by benjk -
Changed lines 6-8 from:
  ( '+' | '-' )? decimalDigit '.' decimalDigit+ scaleFactor ;
to:
  ( '+' | '-' )? decimalDigit '.' digitGroup ( ',' digitGroup )* scaleFactor ;
digitGroup :
  decimalDigit decimalDigit decimalDigit
;
Changed line 15 from:
Example: 1.23456789+E00
to:
Example: 1.234,567,890+E00
2010-01-14 15:59 by benjk -
Added line 12:
Added line 27:
Added line 40:
2010-01-14 15:58 by benjk -
Changed line 3 from:
# Scientific format, defined by the following EBNF:
to:
!!!Scientific format, defined by the following EBNF:
Changed line 14 from:
# Engineering format, defined by the following EBNF:
to:
!!!Engineering format, defined by the following EBNF:
Changed line 28 from:
# Ledger format, defined by the following EBNF:
to:
!!!Ledger format, defined by the following EBNF:
2010-01-14 15:58 by benjk -
Added lines 1-38:
There are multiple formats for textual representation of real numbers
 
# Scientific format, defined by the following EBNF:
[@
sciReal :
  ( '+' | '-' )? decimalDigit '.' decimalDigit+ scaleFactor ;
scaleFactor :
  ( '+' | '-') decimalDigit+ ;
decimalDigit :
  '0' .. '9' ;
@]
Example: 1.23456789+E00

# Engineering format, defined by the following EBNF:
[@
engReal :
  ( '+' | '-' )? decimalDigit decimalDigit? decimalDigit? ( ',' digitGroup )*
  '.' digitGroup ( ',' digitGroup )* engScaleFactor ;
digitGroup :
  decimalDigit decimalDigit decimalDigit ;
engScaleFactor :
  ( '+' | '-' ) digitGroup ;
decimalDigit :
  '0' .. '9' ;
@]
Example: 1,234.456,789E+000

# Ledger format, defined by the following EBNF:
[@
ledgerReal :
  ( '+' | '-' )? decimalDigit decimalDigit? decimalDigit? ( ',' digitGroup )*
  ( '.' decimalDigits+ )?
digitGroup :
  decimalDigit decimalDigit decimalDigit ;
decimalDigit :
  '0' .. '9' ;
@]
Example: 1,234,456.00