Debian Codegraph @

gcc/m2/gm2-libs-log/RealConversions.def

raw
1 (* RealConversions.def provides a Logitech-3.0 compatible module.
2
3 Copyright (C) 2005-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 DEFINITION MODULE RealConversions ;
28
29 EXPORT QUALIFIED SetNoOfExponentDigits,
30 RealToString, StringToReal,
31 LongRealToString, StringToLongReal ;
32
33
34 (*
35 SetNoOfExponentDigits - sets the number of exponent digits to be
36 used during future calls of LongRealToString
37 and RealToString providing that the width
38 is sufficient.
39 If this value is set to 0 (the default) then
40 the number digits used is the minimum necessary.
41 *)
42
43 PROCEDURE SetNoOfExponentDigits (places: CARDINAL) ;
44
45
46 (*
47 RealToString - converts a real, r, into a right justified string, str.
48 The number of digits to the right of the decimal point
49 is given in, digits. The value, width, represents the
50 maximum number of characters to be used in the string,
51 str.
52
53 If digits is negative then exponent notation is used
54 whereas if digits is positive then fixed point notation
55 is used.
56
57 If, r, is less than 0.0 then a '-' preceeds the value,
58 str. However, if, r, is >= 0.0 a '+' is not added.
59
60 If the conversion of, r, to a string requires more
61 than, width, characters then the string, str, is set
62 to a nul string and, ok is assigned FALSE.
63
64 For fixed point notation the minimum width required is
65 ABS(width)+8
66
67 For exponent notation the minimum width required is
68 ABS(digits)+2+log10(magnitude).
69
70 if r is a NaN then the string 'nan' is returned formatted and
71 ok will be FALSE.
72 *)
73
74 PROCEDURE RealToString (r: REAL; digits, width: INTEGER;
75 VAR str: ARRAY OF CHAR; VAR ok: BOOLEAN) ;
76
77
78 (*
79 LongRealToString - converts a real, r, into a right justified string, str.
80 The number of digits to the right of the decimal point
81 is given in, digits. The value, width, represents the
82 maximum number of characters to be used in the string,
83 str.
84
85 If digits is negative then exponent notation is used
86 whereas if digits is positive then fixed point notation
87 is used.
88
89 If, r, is less than 0.0 then a '-' preceeds the value,
90 str. However, if, r, is >= 0.0 a '+' is not added.
91
92 If the conversion of, r, to a string requires more
93 than, width, characters then the string, str, is set
94 to a nul string and, ok is assigned FALSE.
95
96 For fixed point notation the minimum width required is
97 ABS(width)+8
98
99 For exponent notation the minimum width required is
100 ABS(digits)+2+log10(magnitude).
101
102 Examples:
103 RealToString(100.0, 10, 10, a, ok) -> '100.000000'
104 RealToString(100.0, -5, 12, a, ok) -> ' 1.00000E+2'
105
106 RealToString(123.456789, 10, 10, a, ok) -> '123.456789'
107 RealToString(123.456789, -5, 13, a, ok) -> ' 1.23456E+2'
108
109 RealToString(123.456789, -2, 15, a, ok) -> ' 1.23E+2'
110
111 if r is a NaN then the string 'nan' is returned formatted and
112 ok will be FALSE.
113 *)
114
115 PROCEDURE LongRealToString (r: LONGREAL; digits, width: INTEGER;
116 VAR str: ARRAY OF CHAR; VAR ok: BOOLEAN) ;
117
118
119 (*
120 StringToReal - converts, str, into a REAL, r. The parameter, ok, is
121 set to TRUE if the conversion was successful.
122 *)
123
124 PROCEDURE StringToReal (str: ARRAY OF CHAR; VAR r: REAL; VAR ok: BOOLEAN) ;
125
126
127 (*
128 StringToLongReal - converts, str, into a LONGREAL, r. The parameter, ok, is
129 set to TRUE if the conversion was successful.
130 *)
131
132 PROCEDURE StringToLongReal (str: ARRAY OF CHAR; VAR r: LONGREAL; VAR ok: BOOLEAN) ;
133
134
135 END RealConversions.