Debian Codegraph @

gcc/m2/gm2-libs-iso/ShortIO.mod

raw
1 (* ShortIO.mod implements input/output of SHORTREAL over channels.
2
3 Copyright (C) 2013-2025 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <[email protected]>.
5
6 This file is part of GNU Modula-2.
7
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
21
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. *)
26
27 IMPLEMENTATION MODULE ShortIO;
28
29 IMPORT RealIO ;
30
31 (* The text form of a signed fixed-point real number is
32 ["+" | "-"], decimal digit, {decimal digit},
33 [".", {decimal digit}]
34
35 The text form of a signed floating-point real number is
36 signed fixed-point real number,
37 "E", ["+" | "-"], decimal digit, {decimal digit}
38 *)
39
40 (* Skips leading spaces, and removes any remaining characters
41 from cid that form part of a signed fixed or floating
42 point number. The value of this number is assigned to real.
43 The read result is set to the value allRight, outOfRange,
44 wrongFormat, endOfLine, or endOfInput.
45 *)
46
47 PROCEDURE ReadReal (cid: IOChan.ChanId; VAR real: SHORTREAL);
48 VAR
49 r: REAL ;
50 BEGIN
51 RealIO.ReadReal(cid, r) ;
52 real := r
53 END ReadReal ;
54
55
56 (* Writes the value of real to cid in floating-point text form,
57 with sigFigs significant figures, in a field of the given
58 minimum width.
59 *)
60
61 PROCEDURE WriteFloat (cid: IOChan.ChanId; real: SHORTREAL;
62 sigFigs: CARDINAL; width: CARDINAL);
63 BEGIN
64 RealIO.WriteFloat(cid, real, sigFigs, width)
65 END WriteFloat ;
66
67
68 (* As for WriteFloat, except that the number is scaled with
69 one to three digits in the whole number part, and with an
70 exponent that is a multiple of three.
71 *)
72
73 PROCEDURE WriteEng (cid: IOChan.ChanId; real: SHORTREAL;
74 sigFigs: CARDINAL; width: CARDINAL);
75 BEGIN
76 RealIO.WriteEng(cid, real, sigFigs, width)
77 END WriteEng ;
78
79
80 (* Writes the value of real to cid in fixed-point text form,
81 rounded to the given place relative to the decimal point,
82 in a field of the given minimum width.
83 *)
84
85 PROCEDURE WriteFixed (cid: IOChan.ChanId; real: SHORTREAL;
86 place: INTEGER; width: CARDINAL);
87 BEGIN
88 RealIO.WriteFixed(cid, real, place, width)
89 END WriteFixed ;
90
91
92 (* Writes the value of real to cid, as WriteFixed if the sign
93 and magnitude can be shown in the given width, or otherwise
94 as WriteFloat. The number of places or significant digits
95 depends on the given width.
96 *)
97
98 PROCEDURE WriteReal (cid: IOChan.ChanId;
99 real: SHORTREAL; width: CARDINAL);
100 BEGIN
101 RealIO.WriteReal(cid, real, width)
102 END WriteReal ;
103
104
105 END ShortIO.