| 1 |
(* Library module defined by the International Standard |
| 2 |
Information technology - programming languages |
| 3 |
BS ISO/IEC 10514-1:1996E Part 1: Modula-2, Base Language. |
| 4 |
|
| 5 |
Copyright ISO/IEC (International Organization for Standardization |
| 6 |
and International Electrotechnical Commission) 1996-2021. |
| 7 |
|
| 8 |
It may be freely copied for the purpose of implementation (see page |
| 9 |
707 of the Information technology - Programming languages Part 1: |
| 10 |
Modula-2, Base Language. BS ISO/IEC 10514-1:1996). *) |
| 11 |
|
| 12 |
DEFINITION MODULE SRealIO; |
| 13 |
|
| 14 |
(* Input and output of real numbers in decimal text form over |
| 15 |
default channels. The read result is of the type |
| 16 |
IOConsts.ReadResults. |
| 17 |
*) |
| 18 |
|
| 19 |
(* The text form of a signed fixed-point real number is |
| 20 |
["+" | "-"], decimal digit, {decimal digit}, |
| 21 |
[".", {decimal digit}] |
| 22 |
|
| 23 |
The text form of a signed floating-point real number is |
| 24 |
signed fixed-point real number, |
| 25 |
"E", ["+" | "-"], decimal digit, {decimal digit} |
| 26 |
*) |
| 27 |
|
| 28 |
PROCEDURE ReadReal (VAR real: REAL); |
| 29 |
(* Skips leading spaces, and removes any remaining characters |
| 30 |
from the default input channel that form part of a signed |
| 31 |
fixed or floating point number. The value of this number |
| 32 |
is assigned to real. The read result is set to the value |
| 33 |
allRight, outOfRange, wrongFormat, endOfLine, or endOfInput. |
| 34 |
*) |
| 35 |
|
| 36 |
PROCEDURE WriteFloat (real: REAL; sigFigs: CARDINAL; width: CARDINAL); |
| 37 |
(* Writes the value of real to the default output channel in |
| 38 |
floating-point text form, with sigFigs significant figures, |
| 39 |
in a field of the given minimum width. |
| 40 |
*) |
| 41 |
|
| 42 |
PROCEDURE WriteEng (real: REAL; sigFigs: CARDINAL; width: CARDINAL); |
| 43 |
(* As for WriteFloat, except that the number is scaled with one to |
| 44 |
three digits in the whole number part, and with an exponent that |
| 45 |
is a multiple of three. |
| 46 |
*) |
| 47 |
|
| 48 |
PROCEDURE WriteFixed (real: REAL; place: INTEGER; width: CARDINAL); |
| 49 |
(* Writes the value of real to the default output channel in |
| 50 |
fixed-point text form, rounded to the given place relative |
| 51 |
to the decimal point, in a field of the given minimum width. |
| 52 |
*) |
| 53 |
|
| 54 |
PROCEDURE WriteReal (real: REAL; width: CARDINAL); |
| 55 |
(* Writes the value of real to the default output channel, as |
| 56 |
WriteFixed if the sign and magnitude can be shown in the |
| 57 |
given width, or otherwise as WriteFloat. The number of |
| 58 |
places or significant digits depends on the given width. |
| 59 |
*) |
| 60 |
|
| 61 |
END SRealIO. |
| 62 |
|