File: test_cpp_complex.mw

package info (click to toggle)
mwrap 1.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 980 kB
  • sloc: cpp: 3,271; ansic: 856; makefile: 252; lex: 233; sh: 2
file content (23 lines) | stat: -rw-r--r-- 622 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function test_cpp_complex;

$ #include <complex>
$ using std::complex;
$ using std::conj;
$
$ complex<double> zsum(complex<double>* zarray, int n) {
$     complex<double> sum(0);
$     for (int i = 0; i < n; ++i) sum += zarray[i];
$     return sum;
$ }

zarray = rand(10,1) + 1i*rand(10,1);
n = length(zarray);
# dcomplex result = zsum(dcomplex[] zarray, int n);
tassert(abs(result-sum(zarray)) < 1e-10*norm(zarray), 'C++ complex support');
# dcomplex cresult = conj(dcomplex result);
tassert(conj(result) == cresult, 'C++ complex support (2)');


function tassert(pred, msg)
if ~pred, fprintf('Failure: %s\n', msg); end