@@ -157,16 +157,17 @@ end
157
157
TA = eltype (A)
158
158
159
159
@inbounds if A. uplo == ' U'
160
- if ! iszero (a[3 ]) # A is not diagonal
160
+ abs2a3 = abs2 (a[3 ])
161
+ if ! iszero (abs2a3) # A is not diagonal
161
162
t_half = real (a[1 ] + a[4 ]) / 2
162
- d = real (a[1 ] * a[4 ] - a[ 3 ] ' * a[ 3 ] ) # Should be real
163
+ d = real (a[1 ] * a[4 ] - abs2a3 ) # Should be real
163
164
164
165
tmp2 = t_half * t_half - d
165
166
tmp = tmp2 < 0 ? zero (tmp2) : sqrt (tmp2) # Numerically stable for identity matrices, etc.
166
167
vals = SVector (t_half - tmp, t_half + tmp)
167
168
168
169
v11 = vals[1 ] - a[4 ]
169
- n1 = sqrt (v11' * v11 + a[ 3 ] ' * a[ 3 ])
170
+ n1 = sqrt (abs2 ( v11) + abs2a3) # always > 0
170
171
v11 = v11 / n1
171
172
v12 = a[3 ]' / n1
172
173
@@ -176,16 +177,17 @@ end
176
177
return Eigen (vals, vecs)
177
178
end
178
179
else # A.uplo == 'L'
179
- if ! iszero (a[2 ]) # A is not diagonal
180
+ abs2a2 = abs2 (a[2 ])
181
+ if ! iszero (abs2a2) # A is not diagonal
180
182
t_half = real (a[1 ] + a[4 ]) / 2
181
- d = real (a[1 ] * a[4 ] - a[ 2 ] ' * a[ 2 ] ) # Should be real
183
+ d = real (a[1 ] * a[4 ] - abs2a2 ) # Should be real
182
184
183
185
tmp2 = t_half * t_half - d
184
186
tmp = tmp2 < 0 ? zero (tmp2) : sqrt (tmp2) # Numerically stable for identity matrices, etc.
185
187
vals = SVector (t_half - tmp, t_half + tmp)
186
188
187
189
v11 = vals[1 ] - a[4 ]
188
- n1 = sqrt (v11' * v11 + a[ 2 ] ' * a[ 2 ])
190
+ n1 = sqrt (abs2 ( v11) + abs2a2) # always > 0
189
191
v11 = v11 / n1
190
192
v12 = a[2 ] / n1
191
193
196
198
end
197
199
end
198
200
199
- # A must be diagonal if we reached this point; treatment of uplo 'L' and 'U' is then identical
201
+ # A must be diagonal (or computation of abs2 underflowed) if we reached this point;
202
+ # treatment of uplo 'L' and 'U' is then identical
200
203
A11 = real (a[1 ])
201
204
A22 = real (a[4 ])
202
205
if A11 < A22
0 commit comments