@@ -129,7 +129,7 @@ subroutine CLARTG( f, g, c, s, r )
129
129
complex (wp) f, g, r, s
130
130
! ..
131
131
! .. Local Scalars ..
132
- real (wp) :: d, f1, f2, g1, g2, h2, p, u, uu, v, vv , w
132
+ real (wp) :: d, f1, f2, g1, g2, h2, u, v , w
133
133
complex (wp) :: fs, gs, t
134
134
! ..
135
135
! .. Intrinsic Functions ..
@@ -154,19 +154,16 @@ subroutine CLARTG( f, g, c, s, r )
154
154
!
155
155
! Use unscaled algorithm
156
156
!
157
- g2 = ABSSQ( g )
158
- d = sqrt ( g2 )
157
+ d = abs ( g )
159
158
s = conjg ( g ) / d
160
159
r = d
161
160
else
162
161
!
163
162
! Use scaled algorithm
164
163
!
165
164
u = min ( safmax, max ( safmin, g1 ) )
166
- uu = one / u
167
- gs = g* uu
168
- g2 = ABSSQ( gs )
169
- d = sqrt ( g2 )
165
+ gs = g / u
166
+ d = abs ( gs )
170
167
s = conjg ( gs ) / d
171
168
r = d* u
172
169
end if
@@ -181,60 +178,71 @@ subroutine CLARTG( f, g, c, s, r )
181
178
f2 = ABSSQ( f )
182
179
g2 = ABSSQ( g )
183
180
h2 = f2 + g2
184
- if ( f2 > rtmin .and. h2 < rtmax ) then
185
- d = sqrt ( f2* h2 )
186
- else
187
- d = sqrt ( f2 )* sqrt ( h2 )
188
- end if
189
- p = 1 / d
190
181
if ( f2 > safmin * g2 ) then
191
- c = 1 / sqrt ( one + g2/ f2 )
182
+ d = sqrt ( one + g2/ f2 )
183
+ c = one / d
184
+ if ( f2 > rtmin .and. h2 < rtmax ) then
185
+ s = conjg ( g )* ( f / sqrt ( f2* h2 ) )
186
+ else
187
+ s = conjg ( g )* ( f / ( f2* d ) )
188
+ end if
189
+ r = f * d
192
190
else
193
- c = f2* p
191
+ if ( f2 > rtmin .and. h2 < rtmax ) then
192
+ d = sqrt ( f2* h2 )
193
+ else
194
+ d = sqrt ( f2 )* sqrt ( h2 )
195
+ end if
196
+ c = f2 / d
197
+ s = conjg ( g )* ( f / d )
198
+ r = f* ( h2 / d )
194
199
end if
195
- s = conjg ( g )* ( f* p )
196
- r = f* ( h2* p )
197
200
else
198
201
!
199
202
! Use scaled algorithm
200
203
!
201
204
u = min ( safmax, max ( safmin, f1, g1 ) )
202
- uu = one / u
203
- gs = g* uu
205
+ gs = g / u
204
206
g2 = ABSSQ( gs )
205
- if ( f1* uu < rtmin ) then
207
+ if ( f1 < rtmin * u ) then
206
208
!
207
209
! f is not well-scaled when scaled by g1.
208
210
! Use a different scaling for f.
209
211
!
210
212
v = min ( safmax, max ( safmin, f1 ) )
211
- vv = one / v
212
- w = v * uu
213
- fs = f* vv
213
+ w = v / u
214
+ fs = f / v
214
215
f2 = ABSSQ( fs )
215
216
h2 = f2* w** 2 + g2
216
217
else
217
218
!
218
219
! Otherwise use the same scaling for f and g.
219
220
!
220
221
w = one
221
- fs = f* uu
222
+ fs = f / u
222
223
f2 = ABSSQ( fs )
223
224
h2 = f2 + g2
224
225
end if
225
- if ( f2 > rtmin .and. h2 < rtmax ) then
226
- d = sqrt ( f2* h2 )
227
- else
228
- d = sqrt ( f2 )* sqrt ( h2 )
229
- end if
230
- p = 1 / d
231
226
if ( f2 > safmin * g2 ) then
232
- c = (1 / sqrt ( one + g2/ f2 )) * w
227
+ ! Use a precise algorithm
228
+ d = sqrt ( w** 2 + g2/ f2 )
229
+ c = w / d
230
+ if ( f2 > rtmin .and. h2 < rtmax ) then
231
+ s = conjg ( gs )* ( fs / sqrt ( f2* h2 ) )
232
+ else
233
+ s = conjg ( gs )* ( fs / ( f2* d ) )
234
+ end if
235
+ r = ( fs * d ) * u
233
236
else
234
- c = ( f2* p )* w
237
+ if ( f2 > rtmin .and. h2 < rtmax ) then
238
+ d = sqrt ( f2* h2 )
239
+ else
240
+ d = sqrt ( f2 )* sqrt ( h2 )
241
+ end if
242
+ c = ( f2 / d )* w
243
+ s = conjg ( gs )* ( fs / d )
244
+ r = ( fs* ( h2 / d ) )* u
235
245
end if
236
- s = conjg ( gs )* ( fs* p )
237
- r = ( fs* ( h2* p ) )* u
238
246
end if
239
247
end if
240
248
return
0 commit comments