-
Notifications
You must be signed in to change notification settings - Fork 59
/
real_precision.html
346 lines (314 loc) · 10.5 KB
/
real_precision.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<html>
<head>
<title>
REAL_PRECISION - Choosing the Precision of Real Arithmetic
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
REAL_PRECISION <br> Choosing the Precision of Real Arithmetic
</h1>
<hr>
<p>
<b>REAL_PRECISION</b>
is a directory of FORTRAN90 programs which
illustrate the procedure for choosing the precision with which
real variables and constants are stored.
</p>
<p>
FORTRAN90 added a number of arithmetic inquiry functions:
<ul>
<li>
HUGE() returns the largest value of the given type.
</li>
<li>
TINY() returns the smallest value of the given type.
</li>
<li>
EPSILON() returns the precision of a real type.
</li>
<li>
DIGITS() counts the significant binary digits.
</li>
<li>
RANGE() provides the decimal exponent range.
</li>
<li>
PRECISION() provides the decimal precision.
</li>
<li>
RADIX() provides the base of the model.
</li>
<li>
MAXEXPONENT() returns the maximum exponent of a variable.
</li>
<li>
MINEXPONENT() returns the minimum exponent of a variable.
</li>
<li>
KIND() returns the "kind" of a variable.
</li>
</ul>
</p>
<p>
The function <b>ID = SELECTED_REAL_KIND(P,R)</b> can be used to request a
"kind" (which will be an integer) that identifies a real type
with the given number of decimal digits of precision and
exponent range.
</p>
<p>
Sadly, the reality is that each compiler is free to
choose the values of ID that are valid, as well as the number
and properties of its real data types. The only requirement is
that there be at least two real types, with one
more accurate than the other! Moreover, for historical reasons,
any compiler may support nonstandard types, such as REAL*16.
Thus, if you are used to hardcoding declarations such as
"real ( kind = 8 ) x", the fact that they work on your system
is no guarantee they will even compile on another compiler.
</p>
<p>
Only the use of the <b>selected_real_kind</b> function allows
you to write code that will at least compile, if not run.
(It might not run because the precision you requested might
not be available. My compiler returns a -1 in that case for
the identifier, and if I use that identifier as the kind value,
the program aborts.)
</p>
<p>
Real variables can be declared to have a particular type using
a declaration such as <b>real ( kind = id ) r</b>
</p>
<p>
Constants can be specified to beof the given type by appending
an underscore and the kind identifier:
<pre>
1.0_id
3.14159_id
1.0E+17_id
</pre>
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../f_src/f90/f90.html">
F90</a>,
FORTRAN90 programs which
illustrate features of the FORTRAN90 language.
</p>
<p>
<a href = "../../f_src/g95_quadmath/g95_quadmath.html">
G95_QUADMATH</a>,
a FORTRAN90 program which
illustrates the use of quadruple precision real arithmetic
provided on some systems by the G95 compiler for FORTRAN.
</p>
<p>
<a href = "../../f_src/gfortran_quadmath/gfortran_quadmath.html">
GFORTRAN_QUADMATH</a>,
a FORTRAN90 program which
illustrates the use of quadruple precision real arithmetic
provided on some systems by the Gnu GFORTRAN compiler for FORTRAN90.
</p>
<h3 align = "center">
Reference:
</h3>
<p>
<ol>
<li>
Jeanne Adams, Walter Brainerd, Jeanne Martin, Brian Smith,
Jerrold Wagener,<br>
Fortran90 Handbook,<br>
Complete ANSI/ISO Reference,<br>
McGraw Hill, 1992,<br>
ISBN: 0-07-000406-4,<br>
LC: QA76.73.F28.F67.
</li>
<li>
Ian Chivers, Jane Sleightholme,<br>
Introduction to Programming with Fortran,<br>
Springer, 2005,<br>
ISBN: 1846280532,<br>
LC: QA76.73.F29.C48.
</li>
<li>
Miles Ellis, Ivor Philips, Thomas Lahey,<br>
Fortran90 Programming,<br>
Addison-Wesley, 1994,<br>
ISBN: 0-201-54446-6,<br>
LC: QA76.73.F25E435.
</li>
<li>
Michael Metcalf,<br>
Fortran95/2003 Explained,<br>
Oxford, 2004,<br>
ISBN: 0198526938,<br>
LC: QA76.73.F235.M48.
</li>
<li>
Larry Nyhoff, Sanford Leestma,<br>
Introduction to Fortran90 for Engineers and Scientists,<br>
Prentice-Hall, 1996,<br>
ISBN: 0135052157,<br>
LC: QA76.73.F25N925.
</li>
<li>
James Ortega,<br>
An Introduction to FORTRAN90 for Scientific Computing,<br>
Oxford, 1994,<br>
ISBN: 0-19-517213-2,<br>
LC: QA76.73.O75.
</li>
<li>
GNU,<br>
GFORTRAN Reference Manual,<br>
<a href = "../../pdf/gfortran.pdf">gfortran.pdf</a>.
</li>
<li>
GNU,<br>
G95 Reference Manual,<br>
<a href = "../../pdf/g95_manual.pdf">g95_manual.pdf</a>.
</li>
<li>
IBM Corporation,<br>
XLF Language Reference Manual
</li>
<li>
Intel Corporation,<br>
Intel Fortran Language Reference.
</li>
</ol>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<b>REAL_KIND16</b> attempts to declare single, double and quadruple
precision real data using the NONSTANDARD statements REAL ( KIND = 4 ),
REAL ( KIND = 8 ), and REAL ( KIND = 16 ). The G95 compiler seems
to support this language, while GFORTRAN does not.
<ul>
<li>
<a href = "real_kind16.f90">real_kind16.f90</a>, the source code;
</li>
<li>
<a href = "real_kind16.sh">real_kind16.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "real_kind16_output.txt">real_kind16_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>REAL_KIND_DEFAULT</b> declares a real variable of default
type and then uses inquiry functions to determine the characteristics
of that type.
<ul>
<li>
<a href = "real_kind_default.f90">real_kind_default.f90</a>, the source code;
</li>
<li>
<a href = "real_kind_default.sh">real_kind_default.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "real_kind_default_output.txt">real_kind_default_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>REAL_KIND_PRECISION6</b> requests a real type that guarantees a
precision of 6 decimal digits, and uses inquiry functions to determine
the characteristics of that type.
<ul>
<li>
<a href = "real_kind_precision6.f90">real_kind_precision6.f90</a>, the source code;
</li>
<li>
<a href = "real_kind_precision6.sh">real_kind_precision6.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "real_kind_precision6_output.txt">real_kind_precision6_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>REAL_KIND_PRECISION12</b> requests a real type that guarantees a
precision of 12 decimal digits, and uses inquiry functions to determine
the characteristics of that type.
<ul>
<li>
<a href = "real_kind_precision12.f90">real_kind_precision12.f90</a>, the source code;
</li>
<li>
<a href = "real_kind_precision12.sh">real_kind_precision12.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "real_kind_precision12_output.txt">real_kind_precision12_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>REAL_KIND_PRECISION18</b> requests a real type that guarantees a
precision of 18 decimal digits, and uses inquiry functions to determine
the characteristics of that type.
<ul>
<li>
<a href = "real_kind_precision18.f90">real_kind_precision18.f90</a>, the source code;
</li>
<li>
<a href = "real_kind_precision18.sh">real_kind_precision18.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "real_kind_precision18_output.txt">real_kind_precision18_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
<b>REAL_KIND_PRECISION24</b> requests a real type that guarantees a
precision of 24 decimal digits, and uses inquiry functions to determine
the characteristics of that type. This request FAILS with the GFORTRAN
compiler, but succeeds with the G95 compiler.
<ul>
<li>
<a href = "real_kind_precision24.f90">real_kind_precision24.f90</a>, the source code;
</li>
<li>
<a href = "real_kind_precision24.sh">real_kind_precision24.sh</a>, commands that
compile and run the source code;
</li>
<li>
<a href = "real_kind_precision24_output.txt">real_kind_precision24_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../f_src.html">
the FORTRAN90 source codes</a>.
</p>
<hr>
<i>
Last revised on 17 February 2010.
</i>
<!-- John Burkardt -->
</body>
</html>