xfail scan-tree-dump-not throw in g++.dg/pr99966.C on hppa*64*-*-*
[official-gcc.git] / gcc / m2 / gm2-libs / FpuIO.mod
blob6fd2857450889132cd955a19f17c36c935d7a296
1 (* FpuIO.mod implements a fixed format input/output for REAL/LONGREAL.
3 Copyright (C) 2001-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
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.
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.
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.
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/>. *)
27 IMPLEMENTATION MODULE FpuIO ;
29 FROM StrIO IMPORT ReadString, WriteString, WriteLn ;
30 FROM StrLib IMPORT StrLen, StrRemoveWhitePrefix ;
31 FROM ASCII IMPORT nul ;
32 FROM DynamicStrings IMPORT String, InitString, KillString, CopyOut,
33 InitStringDB, InitStringCharStarDB,
34 InitStringCharDB, MultDB, DupDB, SliceDB ;
36 FROM StringConvert IMPORT StringToLongreal, LongrealToString,
37 LongIntegerToString, StringToLongInteger ;
40 #undef GM2_DEBUG_FPUIO
41 if defined(GM2_DEBUG_FPUIO)
42 # define InitString(X) InitStringDB(X, __FILE__, __LINE__)
43 # define InitStringCharStar(X) InitStringCharStarDB(X, __FILE__, __LINE__)
44 # define InitStringChar(X) InitStringCharDB(X, __FILE__, __LINE__)
45 # define Mult(X,Y) MultDB(X, Y, __FILE__, __LINE__)
46 # define Dup(X) DupDB(X, __FILE__, __LINE__)
47 # define Slice(X,Y,Z) SliceDB(X, Y, Z, __FILE__, __LINE__)
48 #endif
52 CONST
53 MaxLineLength = 100 ;
56 PROCEDURE ReadReal (VAR x: REAL) ;
57 VAR
58 a: ARRAY [0..MaxLineLength] OF CHAR ;
59 BEGIN
60 ReadString(a) ;
61 StrToReal(a, x)
62 END ReadReal ;
66 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
67 FractionWidth into, string, a.
70 PROCEDURE WriteReal (x: REAL; TotalWidth, FractionWidth: CARDINAL) ;
71 VAR
72 a: ARRAY [0..MaxLineLength] OF CHAR ;
73 BEGIN
74 RealToStr(x, TotalWidth, FractionWidth, a) ;
75 WriteString(a)
76 END WriteReal ;
79 PROCEDURE StrToReal (a: ARRAY OF CHAR ; VAR x: REAL) ;
80 VAR
81 lr: LONGREAL ;
82 BEGIN
83 StrToLongReal(a, lr) ; (* let StrToLongReal do the work and we convert the result back to REAL *)
84 x := VAL(REAL, lr)
85 END StrToReal ;
88 PROCEDURE ReadLongReal (VAR x: LONGREAL) ;
89 VAR
90 a: ARRAY [0..MaxLineLength] OF CHAR ;
91 BEGIN
92 ReadString(a) ;
93 StrToLongReal(a, x)
94 END ReadLongReal ;
98 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
99 FractionWidth into a string.
102 PROCEDURE WriteLongReal (x: LONGREAL; TotalWidth, FractionWidth: CARDINAL) ;
104 a: ARRAY [0..MaxLineLength] OF CHAR ;
105 BEGIN
106 LongRealToStr(x, TotalWidth, FractionWidth, a) ;
107 WriteString(a)
108 END WriteLongReal ;
111 PROCEDURE StrToLongReal (a: ARRAY OF CHAR ; VAR x: LONGREAL) ;
113 found: BOOLEAN ;
114 s : String ;
115 BEGIN
116 s := InitString(a) ;
117 x := StringToLongreal(s, found) ;
118 s := KillString(s)
119 END StrToLongReal ;
123 RealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
124 FractionWidth into a string.
127 PROCEDURE RealToStr (x: REAL; TotalWidth, FractionWidth: CARDINAL; VAR a: ARRAY OF CHAR) ;
129 lr: LONGREAL ;
130 BEGIN
131 lr := VAL(LONGREAL, x) ;
132 LongRealToStr(lr, TotalWidth, FractionWidth, a)
133 END RealToStr ;
137 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
138 FractionWidth into a string.
141 PROCEDURE LongRealToStr (x: LONGREAL; TotalWidth, FractionWidth: CARDINAL; VAR a: ARRAY OF CHAR) ;
143 s: String ;
144 BEGIN
145 s := LongrealToString(x, TotalWidth, FractionWidth) ;
146 CopyOut(a, s) ;
147 s := KillString(s)
148 END LongRealToStr ;
151 PROCEDURE ReadLongInt (VAR x: LONGINT) ;
153 a : ARRAY [0..MaxLineLength] OF CHAR ;
154 BEGIN
155 ReadString( a ) ;
156 StrToLongInt(a, x)
157 END ReadLongInt ;
160 PROCEDURE WriteLongInt (x: LONGINT; n: CARDINAL) ;
162 a : ARRAY [0..MaxLineLength] OF CHAR ;
163 BEGIN
164 LongIntToStr(x, n, a) ;
165 WriteString(a)
166 END WriteLongInt ;
169 PROCEDURE LongIntToStr (x: LONGINT; n: CARDINAL ; VAR a: ARRAY OF CHAR) ;
171 s: String ;
172 BEGIN
173 s := LongIntegerToString(x, n, ' ', FALSE, 10, TRUE) ;
174 CopyOut(a, s) ;
175 s := KillString(s)
176 END LongIntToStr ;
179 PROCEDURE StrToLongInt (a: ARRAY OF CHAR ; VAR x: LONGINT) ;
181 s : String ;
182 found: BOOLEAN ;
183 BEGIN
184 s := InitString(a) ;
185 x := StringToLongInteger(s, 10, found) ;
186 s := KillString(s)
187 END StrToLongInt ;
190 END FpuIO.