-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmachine_prb.cpp
307 lines (255 loc) · 7.56 KB
/
machine_prb.cpp
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
# include <cstdlib>
# include <iostream>
# include <iomanip>
using namespace std;
# include "machine.hpp"
int main ( );
void d1mach_prb ( );
void i1mach_prb ( );
void r1mach_prb ( );
//****************************************************************************80
int main ( )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for MACHINE_PRB.
//
// Discussion:
//
// MACHINE_PRB tests the MACHINE library.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 24 April 2007
//
// Author:
//
// John Burkardt
//
{
timestamp ( );
cout << "\n";
cout << "MACHINE_PRB:\n";
cout << " C++ version\n";
cout << " Test the MACHINE library.\n";
d1mach_prb ( );
i1mach_prb ( );
r1mach_prb ( );
//
// Terminate.
//
cout << "\n";
cout << "MACHINE_PRB:\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );
return 0;
}
//****************************************************************************80
void d1mach_prb ( )
//****************************************************************************80
//
// Purpose:
//
// D1MACH_PRB reports the constants returned by D1MACH.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 24 April 2007
//
// Author:
//
// John Burkardt
//
{
cout << "\n";
cout << "D1MACH_PRB\n";
cout << " D1MACH reports the value of constants associated\n";
cout << " with real double precision computer arithmetic.\n";
cout << "\n";
cout << " Assume that double precision numbers are stored\n";
cout << " with a mantissa of T digits in base B, with an\n";
cout << " exponent whose value must lie between EMIN and EMAX.\n";
cout << "\n";
cout << " For input arguments of 1 <= I <= 5,\n";
cout << " D1MACH will return the following values:\n";
cout << "\n";
cout << " D1MACH(1) = B^(EMIN-1), the smallest positive magnitude.\n";
cout << setw(26) << setprecision(16) << d1mach(1) << "\n";
cout << "\n";
cout << " D1MACH(2) = B^EMAX*(1-B^(-T)), the largest magnitude.\n";
cout << setw(26) << setprecision(16) << d1mach(2) << "\n";
cout << "\n";
cout << " D1MACH(3) = B^(-T), the smallest relative spacing.\n";
cout << setw(26) << setprecision(16) << d1mach(3) << "\n";
cout << "\n";
cout << " D1MACH(4) = B^(1-T), the largest relative spacing.\n";
cout << setw(26) << setprecision(16) << d1mach(4) << "\n";
cout << "\n";
cout << " D1MACH(5) = log10(B).\n";
cout << setw(26) << setprecision(16) << d1mach(5) << "\n";
return;
}
//****************************************************************************80
void i1mach_prb ( )
//****************************************************************************80
//
// Purpose:
//
// I1MACH_PRB reports the constants returned by I1MACH.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 24 April 2007
//
// Author:
//
// John Burkardt
//
{
cout << "\n";
cout << "I1MACH_PRB\n";
cout << " I1MACH reports the value of constants associated\n";
cout << " with integer computer arithmetic.\n";
cout << "\n";
cout << " Numbers associated with input/output units:\n";
cout << "\n";
cout << " I1MACH(1) = the standard input unit.\n";
cout << i1mach(1) << "\n";
cout << "\n";
cout << " I1MACH(2) = the standard output unit.\n";
cout << i1mach(2) << "\n";
cout << "\n";
cout << " I1MACH(3) = the standard punch unit.\n";
cout << i1mach(3) << "\n";
cout << "\n";
cout << " I1MACH(4) = the standard error message unit.\n";
cout << i1mach(4) << "\n";
cout << "\n";
cout << " Numbers associated with words:\n";
cout << "\n";
cout << " I1MACH(5) = the number of bits per integer.\n";
cout << i1mach(5) << "\n";
cout << "\n";
cout << " I1MACH(6) = the number of characters per integer.\n";
cout << i1mach(6) << "\n";
cout << "\n";
cout << " Numbers associated with integer values:\n";
cout << "\n";
cout << " Assume integers are represented in the S digit \n";
cout << " base A form:\n";
cout << "\n";
cout << " Sign * (X(S-1)*A^(S-1) + ... + X(1)*A + X(0))\n";
cout << "\n";
cout << " where the digits X satisfy 0 <= X(1:S-1) < A.\n";
cout << "\n";
cout << " I1MACH(7) = A, the base.\n";
cout << i1mach(7) << "\n";
cout << "\n";
cout << " I1MACH(8) = S, the number of base A digits.\n";
cout << i1mach(8) << "\n";
cout << "\n";
cout << " I1MACH(9) = A^S-1, the largest integer.\n";
cout << i1mach(9) << "\n";
cout << "\n";
cout << " Numbers associated with floating point values:\n";
cout << "\n";
cout << " Assume floating point numbers are represented \n";
cout << " in the T digit base B form:\n";
cout << "\n";
cout << " Sign * (B**E) * ((X(1)/B) + ... + (X(T)/B^T) )\n";
cout << "\n";
cout << " where\n";
cout << "\n";
cout << " 0 <= X(1:T) < B,\n";
cout << " 0 < X(1) (unless the value being represented is 0),\n";
cout << " EMIN <= E <= EMAX.\n";
cout << "\n";
cout << " I1MACH(10) = B, the base.\n";
cout << i1mach(10) << "\n";
cout << "\n";
cout << " Numbers associated with single precision values:\n";
cout << "\n";
cout << " I1MACH(11) = T, the number of base B digits.\n";
cout << i1mach(11) << "\n";
cout << "\n";
cout << " I1MACH(12) = EMIN, the smallest exponent E.\n";
cout << i1mach(12) << "\n";
cout << "\n";
cout << " I1MACH(13) = EMAX, the largest exponent E.\n";
cout << i1mach(13) << "\n";
cout << "\n";
cout << " Numbers associated with double precision values:\n";
cout << "\n";
cout << " I1MACH(14) = T, the number of base B digits.\n";
cout << i1mach(14) << "\n";
cout << "\n";
cout << " I1MACH(15) = EMIN, the smallest exponent E.\n";
cout << i1mach(15) << "\n";
cout << "\n";
cout << " I1MACH(16) = EMAX, the largest exponent E.\n";
cout << i1mach(16) << "\n";
return;
}
//****************************************************************************80
void r1mach_prb ( )
//****************************************************************************80
//
// Purpose:
//
// R1MACH_PRB reports the constants returned by R1MACH.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 24 April 2007
//
// Author:
//
// John Burkardt
//
{
cout << "\n";
cout << "R1MACH_PRB\n";
cout << " R1MACH reports the value of constants associated\n";
cout << " with real single precision computer arithmetic.\n";
cout << "\n";
cout << " Assume that single precision numbers are stored \n";
cout << " with a mantissa of T digits in base B, with an \n";
cout << " exponent whose value must lie between EMIN and EMAX.\n";
cout << "\n";
cout << " For input arguments of 1 <= I <= 5,\n";
cout << " R1MACH will return the following values:\n";
cout << "\n";
cout << " R1MACH(1) = B^(EMIN-1), the smallest positive magnitude.\n";
cout << setw(26) << setprecision(16) << r1mach(1) << "\n";
cout << "\n";
cout << " R1MACH(2) = B^EMAX*(1-B**(-T)), the largest magnitude.\n";
cout << setw(26) << setprecision(16) << r1mach(2) << "\n";
cout << "\n";
cout << " R1MACH(3) = B^(-T), the smallest relative spacing.\n";
cout << setw(26) << setprecision(16) << r1mach(3) << "\n";
cout << "\n";
cout << " R1MACH(4) = B^(1-T), the largest relative spacing.\n";
cout << setw(26) << setprecision(16) << r1mach(4) << "\n";
cout << "\n";
cout << " R1MACH(5) = log10(B).\n";
cout << setw(26) << setprecision(16) << r1mach(5) << "\n";
return;
}