File: hao-he-mark.cpp

package info (click to toggle)
blitz%2B%2B 1%3A0.10-3.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,276 kB
  • ctags: 12,037
  • sloc: cpp: 70,465; sh: 11,116; fortran: 1,510; python: 1,246; f90: 852; makefile: 701
file content (56 lines) | stat: -rw-r--r-- 986 bytes parent folder | download | duplicates (10)
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
struct Complex {

    Complex(double _re, double _im)
    {
        re = _re;
        im = _im;
    }

    Complex& operator+=(const Complex& a)
    {
        re += a.re;
        im += a.im;
    }

    Complex operator*(const Complex& a) const
    {
        return Complex(re*a.re-im*a.im, re*a.im+im*a.re);
    }

    double real() const { return re; } 
    double imag() const { return im; }

    double re, im;
};

#if 0
inline Complex sqr1(const Complex& a)
{
    return Complex(a.real() * a.real() - a.imag() * a.imag(),
      2 * a.real() * a.imag());
}

inline Complex sqr2(const Complex& a)
{
    return Complex(a.re * a.re - a.im * a.im, 2 * a.re * a.im);
}

inline Complex sqr3(const Complex& a)
{
    double r = a.re;
    double i = a.im;
    return Complex(r*r-i*i, 2*r*i);
}
#endif

void foo(Complex& a, const Complex& b)
{
    a += sqr(b);
}

void foo2(Complex* __restrict__ a, Complex* __restrict__ b, int N)
{
    for (int i=0; i < N; ++i)
        a[i] += sqr(b[i]);
}