41{
42 const int n = 3;
43 std::complex<double> u[n], q[n];
44 std::complex<double> omega, f;
45 double K, h, g;
46
47
48#ifndef EVALS_ONLY
49 for (int i=0; i < n; i++)
50 {
51 Q[i][i] = 1.0;
52 for (int j=0; j < i; j++)
53 Q[i][j] = Q[j][i] = 0.0;
54 }
55#endif
56
57
59 if (real(A[0][1]) > 0)
60 g = -sqrt(h);
61 else
62 g = sqrt(h);
63 e[0] = g;
64 f = g * A[0][1];
65 u[1] = conj(A[0][1]) - g;
66 u[2] = conj(A[0][2]);
67
68 omega = h - f;
69 if (real(omega) > 0.0)
70 {
71 omega = 0.5 * (1.0 + conj(omega)/omega) / real(omega);
72 K = 0.0;
73 for (int i=1; i < n; i++)
74 {
75 f = conj(A[1][i]) * u[1] + A[i][2] * u[2];
76 q[i] = omega * f;
77 K += real(conj(u[i]) * f);
78 }
80
81 for (int i=1; i < n; i++)
82 q[i] = q[i] - K * u[i];
83
84 d[0] = real(A[0][0]);
85 d[1] = real(A[1][1]) - 2.0*real(q[1]*conj(u[1]));
86 d[2] = real(A[2][2]) - 2.0*real(q[2]*conj(u[2]));
87
88
89#ifndef EVALS_ONLY
90 for (int j=1; j < n; j++)
91 {
92 f = omega * conj(u[j]);
93 for (int i=1; i < n; i++)
94 Q[i][j] = Q[i][j] - f*u[i];
95 }
96#endif
97
98
99 f = A[1][2] - q[1]*conj(u[2]) - u[1]*conj(q[2]);
100 }
101 else
102 {
103 for (int i=0; i < n; i++)
104 d[i] = real(A[i][i]);
105 f = A[1][2];
106 }
107
108
109 e[1] = abs(f);
110#ifndef EVALS_ONLY
111 if (e[1] != 0.0)
112 {
113 f = conj(f) / e[1];
114 for (int i=1; i < n; i++)
115 Q[i][n-1] = Q[i][n-1] * f;
116 }
117#endif
118}