-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmachine.cpp
399 lines (376 loc) · 8.19 KB
/
machine.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
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <ctime>
using namespace std;
# include "machine.hpp"
//****************************************************************************80
double d1mach ( int i )
//****************************************************************************80
//
// Purpose:
//
// D1MACH returns double precision real machine constants.
//
// Discussion:
//
// Assuming that the internal representation of a double precision real
// number is in base B, with T the number of base-B digits in the mantissa,
// and EMIN the smallest possible exponent and EMAX the largest possible
// exponent, then
//
// D1MACH(1) = B^(EMIN-1), the smallest positive magnitude.
// D1MACH(2) = B^EMAX*(1-B^(-T)), the largest magnitude.
// D1MACH(3) = B^(-T), the smallest relative spacing.
// D1MACH(4) = B^(1-T), the largest relative spacing.
// D1MACH(5) = log10(B).
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 18 January 2012
//
// Author:
//
// Original FORTRAN77 version by Phyllis Fox, Andrew Hall, Norman Schryer.
// C++ version by John Burkardt.
//
// Reference:
//
// Phyllis Fox, Andrew Hall, Norman Schryer,
// Algorithm 528:
// Framework for a Portable Library,
// ACM Transactions on Mathematical Software,
// Volume 4, Number 2, June 1978, page 176-188.
//
// Parameters:
//
// Input, int I, chooses the parameter to be returned.
// 1 <= I <= 5.
//
// Output, double D1MACH, the value of the chosen parameter.
//
{
double value;
if ( i == 1 )
{
value = 4.450147717014403E-308;
}
else if ( i == 2 )
{
value = 8.988465674311579E+307;
}
else if ( i == 3 )
{
value = 1.110223024625157E-016;
}
else if ( i == 4 )
{
value = 2.220446049250313E-016;
}
else if ( i == 5 )
{
value = 0.301029995663981E+000;
}
else if ( 5 < i )
{
cerr << "\n";
cerr << "D1MACH - Fatal error!\n";
cerr << " The input argument I is out of bounds.\n";
cerr << " Legal values satisfy 1 <= I <= 5.\n";
cerr << " I = " << i << "\n";
value = 0.0;
exit ( 1 );
}
return value;
}
//****************************************************************************80
int i1mach ( int i )
//****************************************************************************80
//
// Purpose:
//
// I1MACH returns integer machine constants.
//
// Discussion:
//
// Input/output unit numbers.
//
// I1MACH(1) = the standard input unit.
// I1MACH(2) = the standard output unit.
// I1MACH(3) = the standard punch unit.
// I1MACH(4) = the standard error message unit.
//
// Words.
//
// I1MACH(5) = the number of bits per integer storage unit.
// I1MACH(6) = the number of characters per integer storage unit.
//
// Integers.
//
// Assume integers are represented in the S digit base A form:
//
// Sign * (X(S-1)*A^(S-1) + ... + X(1)*A + X(0))
//
// where 0 <= X(1:S-1) < A.
//
// I1MACH(7) = A, the base.
// I1MACH(8) = S, the number of base A digits.
// I1MACH(9) = A^S-1, the largest integer.
//
// Floating point numbers
//
// Assume floating point numbers are represented in the T digit
// base B form:
//
// Sign * (B**E) * ((X(1)/B) + ... + (X(T)/B^T) )
//
// where 0 <= X(I) < B for I=1 to T, 0 < X(1) and EMIN <= E <= EMAX.
//
// I1MACH(10) = B, the base.
//
// Single precision
//
// I1MACH(11) = T, the number of base B digits.
// I1MACH(12) = EMIN, the smallest exponent E.
// I1MACH(13) = EMAX, the largest exponent E.
//
// Double precision
//
// I1MACH(14) = T, the number of base B digits.
// I1MACH(15) = EMIN, the smallest exponent E.
// I1MACH(16) = EMAX, the largest exponent E.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 18 January 2012
//
// Author:
//
// Original FORTRAN77 version by Phyllis Fox, Andrew Hall, Norman Schryer.
// C++ version by John Burkardt.
//
// Reference:
//
// Phyllis Fox, Andrew Hall, Norman Schryer,
// Algorithm 528,
// Framework for a Portable Library,
// ACM Transactions on Mathematical Software,
// Volume 4, Number 2, June 1978, page 176-188.
//
// Parameters:
//
// Input, int I, chooses the parameter to be returned.
// 1 <= I <= 16.
//
// Output, int I1MACH, the value of the chosen parameter.
//
{
int value;
if ( i == 1 )
{
value = 5;
}
else if ( i == 2 )
{
value = 6;
}
else if ( i == 3 )
{
value = 7;
}
else if ( i == 4 )
{
value = 6;
}
else if ( i == 5 )
{
value = 32;
}
else if ( i == 6 )
{
value = 4;
}
else if ( i == 7 )
{
value = 2;
}
else if ( i == 8 )
{
value = 31;
}
else if ( i == 9 )
{
value = 2147483647;
}
else if ( i == 10 )
{
value = 2;
}
else if ( i == 11 )
{
value = 24;
}
else if ( i == 12 )
{
value = -125;
}
else if ( i == 13 )
{
value = 128;
}
else if ( i == 14 )
{
value = 53;
}
else if ( i == 15 )
{
value = -1021;
}
else if ( i == 16 )
{
value = 1024;
}
else
{
cerr << "\n";
cerr << "I1MACH - Fatal error!\n";
cerr << " The input argument I is out of bounds.\n";
cerr << " Legal values satisfy 1 <= I <= 16.\n";
cerr << " I = " << i << "\n";
value = 0;
exit ( 1 );
}
return value;
}
//****************************************************************************80
float r1mach ( int i )
//****************************************************************************80
//
// Purpose:
//
// R1MACH returns single precision real machine constants.
//
// Discussion:
//
// Assume that single precision real numbers are stored with a mantissa
// of T digits in base B, with an exponent whose value must lie
// between EMIN and EMAX. Then for values of I between 1 and 5,
// R1MACH will return the following values:
//
// R1MACH(1) = B^(EMIN-1), the smallest positive magnitude.
// R1MACH(2) = B^EMAX*(1-B^(-T)), the largest magnitude.
// R1MACH(3) = B^(-T), the smallest relative spacing.
// R1MACH(4) = B^(1-T), the largest relative spacing.
// R1MACH(5) = log10(B)
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 18 January 2012
//
// Author:
//
// Original FORTRAN77 version by Phyllis Fox, Andrew Hall, Norman Schryer.
// C++ version by John Burkardt.
//
// Reference:
//
// Phyllis Fox, Andrew Hall, Norman Schryer,
// Algorithm 528,
// Framework for a Portable Library,
// ACM Transactions on Mathematical Software,
// Volume 4, Number 2, June 1978, page 176-188.
//
// Parameters:
//
// Input, int I, chooses the parameter to be returned.
// 1 <= I <= 5.
//
// Output, float R1MACH, the value of the chosen parameter.
//
{
float value;
if ( i == 1 )
{
value = 1.1754944E-38;
}
else if ( i == 2 )
{
value = 3.4028235E+38;
}
else if ( i == 3 )
{
value = 5.9604645E-08;
}
else if ( i == 4 )
{
value = 1.1920929E-07;
}
else if ( i == 5 )
{
value = 0.3010300E+00;
}
else
{
cerr << "\n";
cerr << "R1MACH - Fatal error!\n";
cerr << " The input argument I is out of bounds.\n";
cerr << " Legal values satisfy 1 <= I <= 5.\n";
cerr << " I = " << i << "\n";
value = 0.0;
exit ( 1 );
}
return value;
}
//****************************************************************************80
void timestamp ( )
//****************************************************************************80
//
// Purpose:
//
// TIMESTAMP prints the current YMDHMS date as a time stamp.
//
// Example:
//
// 31 May 2001 09:45:54 AM
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 24 September 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// None
//
{
# define TIME_SIZE 40
static char time_buffer[TIME_SIZE];
const struct tm *tm;
size_t len;
time_t now;
now = time ( NULL );
tm = localtime ( &now );
len = strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm );
cout << time_buffer << "\n";
return;
# undef TIME_SIZE
}