51{
52 const int n = 3;
53 double e[3];
54 double g, r, p, f, b, s, c;
55 std::complex<double> t;
56 int nIter;
57 int m;
58
59
61
62
63
64
65
66 for (int l=0; l < n-1; l++)
67 {
68 nIter = 0;
69 while (1)
70 {
71
72
73 for (m=l; m <= n-2; m++)
74 {
75 g = fabs(w[m])+fabs(w[m+1]);
76 if (fabs(e[m]) + g == g)
77 break;
78 }
79 if (m == l)
80 break;
81
82 if (nIter++ >= 30)
83 return -1;
84
85
86 g = (w[l+1] - w[l]) / (e[l] + e[l]);
87 r = sqrt(
SQR(g) + 1.0);
88 if (g > 0)
89 g = w[m] - w[l] + e[l]/(g + r);
90 else
91 g = w[m] - w[l] + e[l]/(g - r);
92
93 s = c = 1.0;
94 p = 0.0;
95 for (int i=m-1; i >= l; i--)
96 {
97 f = s * e[i];
98 b = c * e[i];
99 if (fabs(f) > fabs(g))
100 {
101 c = g / f;
102 r = sqrt(
SQR(c) + 1.0);
103 e[i+1] = f * r;
104 c *= (s = 1.0/r);
105 }
106 else
107 {
108 s = f / g;
109 r = sqrt(
SQR(s) + 1.0);
110 e[i+1] = g * r;
111 s *= (c = 1.0/r);
112 }
113
114 g = w[i+1] - p;
115 r = (w[i] - g)*s + 2.0*c*b;
116 p = s * r;
117 w[i+1] = g + p;
118 g = c*r - b;
119
120
121#ifndef EVALS_ONLY
122 for (int k=0; k < n; k++)
123 {
124 t = Q[k][i+1];
125 Q[k][i+1] = s*Q[k][i] + c*t;
126 Q[k][i] = c*Q[k][i] - s*t;
127 }
128#endif
129 }
130 w[l] -= p;
131 e[l] = g;
132 e[m] = 0.0;
133 }
134 }
135
136 return 0;
137}
void zhetrd3(std::complex< double > A[3][3], std::complex< double > Q[3][3], double d[3], double e[2])