@@ -136,16 +136,17 @@ end
136
136
TA = eltype (A)
137
137
138
138
@inbounds if A. uplo == ' U'
139
- if ! iszero (a[3 ]) # A is not diagonal
139
+ abs2a3 = abs2 (a[3 ])
140
+ if ! iszero (abs2a3) # A is not diagonal
140
141
t_half = real (a[1 ] + a[4 ]) / 2
141
- d = real (a[1 ] * a[4 ] - a[ 3 ] ' * a[ 3 ] ) # Should be real
142
+ d = real (a[1 ] * a[4 ] - abs2a3 ) # Should be real
142
143
143
144
tmp2 = t_half * t_half - d
144
145
tmp = tmp2 < 0 ? zero (tmp2) : sqrt (tmp2) # Numerically stable for identity matrices, etc.
145
146
vals = SVector (t_half - tmp, t_half + tmp)
146
147
147
148
v11 = vals[1 ] - a[4 ]
148
- n1 = sqrt (v11' * v11 + a[ 3 ] ' * a[ 3 ])
149
+ n1 = sqrt (abs2 ( v11) + abs2a3) # always > 0
149
150
v11 = v11 / n1
150
151
v12 = a[3 ]' / n1
151
152
@@ -155,16 +156,17 @@ end
155
156
return (vals, vecs)
156
157
end
157
158
else # A.uplo == 'L'
158
- if ! iszero (a[2 ]) # A is not diagonal
159
+ abs2a2 = abs2 (a[2 ])
160
+ if ! iszero (abs2a2) # A is not diagonal
159
161
t_half = real (a[1 ] + a[4 ]) / 2
160
- d = real (a[1 ] * a[4 ] - a[ 2 ] ' * a[ 2 ] ) # Should be real
162
+ d = real (a[1 ] * a[4 ] - abs2a2 ) # Should be real
161
163
162
164
tmp2 = t_half * t_half - d
163
165
tmp = tmp2 < 0 ? zero (tmp2) : sqrt (tmp2) # Numerically stable for identity matrices, etc.
164
166
vals = SVector (t_half - tmp, t_half + tmp)
165
167
166
168
v11 = vals[1 ] - a[4 ]
167
- n1 = sqrt (v11' * v11 + a[ 2 ] ' * a[ 2 ])
169
+ n1 = sqrt (abs2 ( v11) + abs2a2) # always > 0
168
170
v11 = v11 / n1
169
171
v12 = a[2 ] / n1
170
172
175
177
end
176
178
end
177
179
178
- # A must be diagonal if we reached this point; treatment of uplo 'L' and 'U' is then identical
180
+ # A must be diagonal (or computation of abs2 underflowed) if we reached this point;
181
+ # treatment of uplo 'L' and 'U' is then identical
179
182
A11 = real (a[1 ])
180
183
A22 = real (a[4 ])
181
184
if A11 < A22
0 commit comments