00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016 int clartg_(complex *f, complex *g, real *cs, complex *sn,
00017 complex *r__)
00018 {
00019
00020 integer i__1;
00021 real r__1, r__2, r__3, r__4, r__5, r__6, r__7, r__8, r__9, r__10;
00022 complex q__1, q__2, q__3;
00023
00024
00025 double log(doublereal), pow_ri(real *, integer *), r_imag(complex *),
00026 sqrt(doublereal);
00027 void r_cnjg(complex *, complex *);
00028
00029
00030 real d__;
00031 integer i__;
00032 real f2, g2;
00033 complex ff;
00034 real di, dr;
00035 complex fs, gs;
00036 real f2s, g2s, eps, scale;
00037 integer count;
00038 real safmn2, safmx2;
00039 extern doublereal slapy2_(real *, real *), slamch_(char *);
00040 real safmin;
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 safmin = slamch_("S");
00116 eps = slamch_("E");
00117 r__1 = slamch_("B");
00118 i__1 = (integer) (log(safmin / eps) / log(slamch_("B")) / 2.f);
00119 safmn2 = pow_ri(&r__1, &i__1);
00120 safmx2 = 1.f / safmn2;
00121
00122
00123
00124
00125 r__7 = (r__1 = f->r, dabs(r__1)), r__8 = (r__2 = r_imag(f), dabs(r__2));
00126
00127 r__9 = (r__3 = g->r, dabs(r__3)), r__10 = (r__4 = r_imag(g), dabs(r__4));
00128 r__5 = dmax(r__7,r__8), r__6 = dmax(r__9,r__10);
00129 scale = dmax(r__5,r__6);
00130 fs.r = f->r, fs.i = f->i;
00131 gs.r = g->r, gs.i = g->i;
00132 count = 0;
00133 if (scale >= safmx2) {
00134 L10:
00135 ++count;
00136 q__1.r = safmn2 * fs.r, q__1.i = safmn2 * fs.i;
00137 fs.r = q__1.r, fs.i = q__1.i;
00138 q__1.r = safmn2 * gs.r, q__1.i = safmn2 * gs.i;
00139 gs.r = q__1.r, gs.i = q__1.i;
00140 scale *= safmn2;
00141 if (scale >= safmx2) {
00142 goto L10;
00143 }
00144 } else if (scale <= safmn2) {
00145 if (g->r == 0.f && g->i == 0.f) {
00146 *cs = 1.f;
00147 sn->r = 0.f, sn->i = 0.f;
00148 r__->r = f->r, r__->i = f->i;
00149 return 0;
00150 }
00151 L20:
00152 --count;
00153 q__1.r = safmx2 * fs.r, q__1.i = safmx2 * fs.i;
00154 fs.r = q__1.r, fs.i = q__1.i;
00155 q__1.r = safmx2 * gs.r, q__1.i = safmx2 * gs.i;
00156 gs.r = q__1.r, gs.i = q__1.i;
00157 scale *= safmx2;
00158 if (scale <= safmn2) {
00159 goto L20;
00160 }
00161 }
00162
00163 r__1 = fs.r;
00164
00165 r__2 = r_imag(&fs);
00166 f2 = r__1 * r__1 + r__2 * r__2;
00167
00168 r__1 = gs.r;
00169
00170 r__2 = r_imag(&gs);
00171 g2 = r__1 * r__1 + r__2 * r__2;
00172 if (f2 <= dmax(g2,1.f) * safmin) {
00173
00174
00175
00176 if (f->r == 0.f && f->i == 0.f) {
00177 *cs = 0.f;
00178 r__2 = g->r;
00179 r__3 = r_imag(g);
00180 r__1 = slapy2_(&r__2, &r__3);
00181 r__->r = r__1, r__->i = 0.f;
00182
00183 r__1 = gs.r;
00184 r__2 = r_imag(&gs);
00185 d__ = slapy2_(&r__1, &r__2);
00186 r__1 = gs.r / d__;
00187 r__2 = -r_imag(&gs) / d__;
00188 q__1.r = r__1, q__1.i = r__2;
00189 sn->r = q__1.r, sn->i = q__1.i;
00190 return 0;
00191 }
00192 r__1 = fs.r;
00193 r__2 = r_imag(&fs);
00194 f2s = slapy2_(&r__1, &r__2);
00195
00196
00197 g2s = sqrt(g2);
00198
00199
00200
00201
00202
00203
00204
00205 *cs = f2s / g2s;
00206
00207
00208
00209 r__3 = (r__1 = f->r, dabs(r__1)), r__4 = (r__2 = r_imag(f), dabs(r__2)
00210 );
00211 if (dmax(r__3,r__4) > 1.f) {
00212 r__1 = f->r;
00213 r__2 = r_imag(f);
00214 d__ = slapy2_(&r__1, &r__2);
00215 r__1 = f->r / d__;
00216 r__2 = r_imag(f) / d__;
00217 q__1.r = r__1, q__1.i = r__2;
00218 ff.r = q__1.r, ff.i = q__1.i;
00219 } else {
00220 dr = safmx2 * f->r;
00221 di = safmx2 * r_imag(f);
00222 d__ = slapy2_(&dr, &di);
00223 r__1 = dr / d__;
00224 r__2 = di / d__;
00225 q__1.r = r__1, q__1.i = r__2;
00226 ff.r = q__1.r, ff.i = q__1.i;
00227 }
00228 r__1 = gs.r / g2s;
00229 r__2 = -r_imag(&gs) / g2s;
00230 q__2.r = r__1, q__2.i = r__2;
00231 q__1.r = ff.r * q__2.r - ff.i * q__2.i, q__1.i = ff.r * q__2.i + ff.i
00232 * q__2.r;
00233 sn->r = q__1.r, sn->i = q__1.i;
00234 q__2.r = *cs * f->r, q__2.i = *cs * f->i;
00235 q__3.r = sn->r * g->r - sn->i * g->i, q__3.i = sn->r * g->i + sn->i *
00236 g->r;
00237 q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
00238 r__->r = q__1.r, r__->i = q__1.i;
00239 } else {
00240
00241
00242
00243
00244
00245 f2s = sqrt(g2 / f2 + 1.f);
00246
00247 r__1 = f2s * fs.r;
00248 r__2 = f2s * r_imag(&fs);
00249 q__1.r = r__1, q__1.i = r__2;
00250 r__->r = q__1.r, r__->i = q__1.i;
00251 *cs = 1.f / f2s;
00252 d__ = f2 + g2;
00253
00254 r__1 = r__->r / d__;
00255 r__2 = r_imag(r__) / d__;
00256 q__1.r = r__1, q__1.i = r__2;
00257 sn->r = q__1.r, sn->i = q__1.i;
00258 r_cnjg(&q__2, &gs);
00259 q__1.r = sn->r * q__2.r - sn->i * q__2.i, q__1.i = sn->r * q__2.i +
00260 sn->i * q__2.r;
00261 sn->r = q__1.r, sn->i = q__1.i;
00262 if (count != 0) {
00263 if (count > 0) {
00264 i__1 = count;
00265 for (i__ = 1; i__ <= i__1; ++i__) {
00266 q__1.r = safmx2 * r__->r, q__1.i = safmx2 * r__->i;
00267 r__->r = q__1.r, r__->i = q__1.i;
00268
00269 }
00270 } else {
00271 i__1 = -count;
00272 for (i__ = 1; i__ <= i__1; ++i__) {
00273 q__1.r = safmn2 * r__->r, q__1.i = safmn2 * r__->i;
00274 r__->r = q__1.r, r__->i = q__1.i;
00275
00276 }
00277 }
00278 }
00279 }
00280 return 0;
00281
00282
00283
00284 }