-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathc4_complex_lib_prb.cpp
410 lines (361 loc) · 8.26 KB
/
c4_complex_lib_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
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
399
400
401
402
403
404
405
406
407
408
409
410
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <cmath>
# include <ctime>
using namespace std;
# include "c4_complex_lib.hpp"
int main ( );
void test01 ( );
void test02 ( );
void test03 ( );
void test04 ( );
void test05 ( );
void test06 ( );
void test07 ( );
void timestamp ( );
//****************************************************************************80
int main ( )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for C4_COMPLEX_LIB_PRB.
//
// Discussion:
//
// C4_COMPLEX_LIB_PRB tests the C4_COMPLEX_LIB library.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 27 September 2013
//
// Author:
//
// John Burkardt
//
{
timestamp ( );
cout << "\n";
cout << "C4_COMPLEX_LIB_PRB\n";
cout << " C++ version.\n";
cout << " Test the C4_COMPLEX_LIB library.\n";
test01 ( );
test02 ( );
test03 ( );
test04 ( );
test05 ( );
test06 ( );
test07 ( );
//
// Terminate.
//
cout << "\n";
cout << "C4_COMPLEX_LIB_PRB\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );
return 0;
}
//****************************************************************************80
void test01 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST01 tests c4_complex assignment.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 October 2005
//
{
c4_complex c1;
c4_complex c2;
float d1 = 1.0;
float d2 = 2.0;
cout << "\n";
cout << "TEST01\n";
cout << " Test assignment of a value to c4_complex.\n";
cout << "\n";
cout << " float D1 = " << d1 << "\n";
cout << " float D2 = " << d2 << "\n";
cout << "\n";
c1 = c4_complex ( d1, d2 );
cout << " C1 = c4_complex ( d1, d2 ) = " << c1 << "\n";
c1 = c4_complex ( d1 );
cout << " C1 = c4_complex ( d1 ) = " << c1 << "\n";
c2 = c1;
cout << " C2 = C1 = " << c2 << "\n";
return;
}
//****************************************************************************80
void test02 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST02 tests c4_complex addition.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 October 2005
//
{
c4_complex c1 = c4_complex ( 100.0, 10.0 );
c4_complex c2;
c4_complex c3;
float d1 = 1.0;
c1 = c4_complex ( 100.0, 10.0 );
c2 = c4_complex ( 99.0, 9.0 );
cout << "\n";
cout << "TEST02\n";
cout << " Test c4_complex addition.\n";
cout << "\n";
cout << " float D1 = " << d1 << "\n";
cout << " c4_complex C1 = " << c1 << "\n";
cout << " c4_complex C2 = " << c2 << "\n";
cout << "\n";
c3 = c1 + c2;
cout << " C3 = C1 + C2 = " << c3 << "\n";
c3 = c1 + d1;
cout << " C3 = C1 + D1 = " << c3 << "\n";
c3 = d1 + c1;
cout << " C3 = C1 + D1 = " << c3 << "\n";
c3 = c1 + c1;
cout << " C3 = C1 + C1 = " << c3 << "\n";
return;
}
//****************************************************************************80
void test03 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST03 tests c4_complex subtraction.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 October 2005
//
{
c4_complex c1 = c4_complex ( 100.0, 10.0 );
c4_complex c2;
c4_complex c3;
float d1 = 1.0;
c1 = c4_complex ( 100.0, 10.0 );
c2 = c4_complex ( 99.0, 9.0 );
cout << "\n";
cout << "TEST02\n";
cout << " Test c4_complex addition.\n";
cout << "\n";
cout << " float D1 = " << d1 << "\n";
cout << " c4_complex C1 = " << c1 << "\n";
cout << " c4_complex C2 = " << c2 << "\n";
cout << "\n";
c3 = c1 - c2;
cout << " C3 = C1 - C2 = " << c3 << "\n";
c3 = c1 - d1;
cout << " C3 = C1 - D1 = " << c3 << "\n";
c3 = d1 - c1;
cout << " C3 = C1 - D1 = " << c3 << "\n";
c3 = c1 - c1;
cout << " C3 = C1 - C1 = " << c3 << "\n";
return;
}
//****************************************************************************80
void test04 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST04 tests c4_complex conjugation.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 October 2005
//
{
c4_complex c1 = c4_complex ( 100.0, 10.0 );
c4_complex c2;
c1 = c4_complex ( 100.0, 10.0 );
cout << "\n";
cout << "TEST04\n";
cout << " Test c4_complex conjugation.\n";
cout << "\n";
cout << " c4_complex C1 = " << c1 << "\n";
cout << "\n";
c2 = ~c1;
cout << " C2 = ~C1 = " << c2 << "\n";
return;
}
//****************************************************************************80
void test05 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST05 tests c4_complex multiplication.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 October 2005
//
{
c4_complex c1 = c4_complex ( 1.0, 2.0 );
c4_complex c2 = c4_complex ( 3.0, 4.0 );
c4_complex c3;
float d1 = 5.0;
float d2 = 6.0;
cout << "\n";
cout << "TEST05\n";
cout << " Test c4_complex multiplication.\n";
cout << "\n";
cout << " couble D1 = " << d1 << "\n";
cout << " couble D2 = " << d2 << "\n";
cout << " c4_complex C1 = " << c1 << "\n";
cout << " c4_complex C2 = " << c2 << "\n";
cout << "\n";
c3 = d1 * c1;
cout << " C3 = D1 * C1 = " << c3 << "\n";
c3 = c2 * d2;
cout << " C3 = C2 * D2 = " << c3 << "\n";
c3 = c1 * c2;
cout << " C3 = C1 * C2 = " << c3 << "\n";
return;
}
//****************************************************************************80
void test06 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST06 tests c4_complex division.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 October 2005
//
{
c4_complex c1 = c4_complex ( 1.0, 2.0 );
c4_complex c2 = c4_complex ( 3.0, 4.0 );
c4_complex c3;
float d1 = 5.0;
float d2 = 6.0;
cout << "\n";
cout << "TEST06\n";
cout << " Test c4_complex division.\n";
cout << "\n";
cout << " float D1 = " << d1 << "\n";
cout << " float D2 = " << d2 << "\n";
cout << " c4_complex C1 = " << c1 << "\n";
cout << " c4_complex C2 = " << c2 << "\n";
cout << "\n";
c3 = d1 / c1;
cout << " C3 = D1 / C1 = " << c3 << "\n";
c3 = c2 / d2;
cout << " C3 = C2 / D2 = " << c3 << "\n";
c3 = c1 / c2;
cout << " C3 = C1 / C2 = " << c3 << "\n";
return;
}
//****************************************************************************80
void test07 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST07 tests real and imaginary part retrieval.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 22 October 2005
//
{
c4_complex c1 = c4_complex ( 1.0, 2.0 );
float d1;
cout << "\n";
cout << "TEST07\n";
cout << " Test c4_complex real and imaginary parts.\n";
cout << "\n";
cout << " c4_complex C1 = " << c1 << "\n";
cout << "\n";
d1 = c1.real();
cout << " D1 = C1.real ( ) = " << d1 << "\n";
d1 = c1.imaginary();
cout << " D1 = C1.imaginary ( ) = " << d1 << "\n";
return;
}
//****************************************************************************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
}