xfail scan-tree-dump-not throw in g++.dg/pr99966.C on hppa*64*-*-*
[official-gcc.git] / gcc / m2 / gm2-libs-iso / RealStr.mod
blob67a1108ed51c116789182097d03535d6adcf1c87
1 (* RealStr.mod implement the ISO RealStr specification.
3 Copyright (C) 2009-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 RealStr;
29 (* REAL/string conversions *)
31 IMPORT RealConv ;
33 FROM DynamicStrings IMPORT String, InitString, KillString, Length, CopyOut ;
35 FROM ConvStringReal IMPORT RealToFixedString, RealToFloatString,
36 RealToEngString ;
39 (* the string form of a signed fixed-point real number is
40 ["+" | "-"], decimal digit, {decimal digit}, [".",
41 {decimal digit}]
44 (* the string form of a signed floating-point real number is
45 signed fixed-point real number, "E", ["+" | "-"],
46 decimal digit, {decimal digit}
49 PROCEDURE StrToReal (str: ARRAY OF CHAR; VAR real: REAL;
50 VAR res: ConvResults) ;
51 (* Ignores any leading spaces in str. If the subsequent characters
52 in str are in the format of a signed real number, assigns a
53 corresponding value to real. Assigns a value indicating the
54 format of str to res.
56 BEGIN
57 res := RealConv.FormatReal(str) ;
58 IF res=strAllRight
59 THEN
60 real := RealConv.ValueReal(str)
61 END
62 END StrToReal ;
65 PROCEDURE RealToFloat (real: REAL; sigFigs: CARDINAL;
66 VAR str: ARRAY OF CHAR) ;
67 (* Converts the value of real to floating-point string form, with
68 sigFigs significant figures, and copies the possibly truncated
69 result to str.
71 VAR
72 s: String ;
73 BEGIN
74 s := RealToFloatString(real, sigFigs) ;
75 CopyOut(str, s) ;
76 s := KillString(s)
77 END RealToFloat ;
80 PROCEDURE RealToEng (real: REAL; sigFigs: CARDINAL;
81 VAR str: ARRAY OF CHAR) ;
82 (* Converts the value of real to floating-point string form, with
83 sigFigs significant figures, and copies the possibly truncated
84 result to str. The number is scaled with one to three digits
85 in the whole number part and with an exponent that is a multiple
86 of three.
88 VAR
89 s: String ;
90 BEGIN
91 s := RealToEngString(real, sigFigs) ;
92 CopyOut(str, s) ;
93 s := KillString(s)
94 END RealToEng ;
97 PROCEDURE RealToFixed (real: REAL; place: INTEGER;
98 VAR str: ARRAY OF CHAR) ;
99 (* Converts the value of real to fixed-point string form, rounded
100 to the given place relative to the decimal point, and copies
101 the possibly truncated result to str.
104 s: String ;
105 BEGIN
106 s := RealToFixedString(real, place) ;
107 CopyOut(str, s) ;
108 s := KillString(s)
109 END RealToFixed ;
112 PROCEDURE RealToStr (real: REAL; VAR str: ARRAY OF CHAR) ;
113 (* Converts the value of real as RealToFixed if the sign and
114 magnitude can be shown within the capacity of str, or
115 otherwise as RealToFloat, and copies the possibly truncated
116 result to str. The number of places or significant digits
117 are implementation-defined.
120 s : String ;
121 sigFigs: CARDINAL ;
122 BEGIN
123 sigFigs := HIGH(str) ;
124 WHILE sigFigs>1 DO
125 s := RealToFixedString(real, sigFigs) ;
126 IF Length(s)<=HIGH(str)
127 THEN
128 CopyOut(str, s) ;
129 s := KillString(s) ;
130 RETURN
131 END ;
132 s := KillString(s) ;
133 DEC(sigFigs)
134 END ;
135 sigFigs := HIGH(str) ;
136 WHILE sigFigs#0 DO
137 s := RealToFloatString(real, sigFigs) ;
138 IF Length(s)<=HIGH(str)
139 THEN
140 CopyOut(str, s) ;
141 s := KillString(s) ;
142 RETURN
143 END ;
144 s := KillString(s) ;
145 DEC(sigFigs)
147 END RealToStr ;
150 END RealStr.