/src/igraph/vendor/lapack/dladiv.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* -- translated by f2c (version 20191129). |
2 | | You must link the resulting object file with libf2c: |
3 | | on Microsoft Windows system, link with libf2c.lib; |
4 | | on Linux or Unix systems, link with .../path/to/libf2c.a -lm |
5 | | or, if you install libf2c.a in a standard place, with -lf2c -lm |
6 | | -- in that order, at the end of the command line, as in |
7 | | cc *.o -lf2c -lm |
8 | | Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., |
9 | | |
10 | | http://www.netlib.org/f2c/libf2c.zip |
11 | | */ |
12 | | |
13 | | #include "f2c.h" |
14 | | |
15 | | /* > \brief \b DLADIV performs complex division in real arithmetic, avoiding unnecessary overflow. |
16 | | |
17 | | =========== DOCUMENTATION =========== |
18 | | |
19 | | Online html documentation available at |
20 | | http://www.netlib.org/lapack/explore-html/ |
21 | | |
22 | | > \htmlonly |
23 | | > Download DLADIV + dependencies |
24 | | > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dladiv. |
25 | | f"> |
26 | | > [TGZ]</a> |
27 | | > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dladiv. |
28 | | f"> |
29 | | > [ZIP]</a> |
30 | | > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dladiv. |
31 | | f"> |
32 | | > [TXT]</a> |
33 | | > \endhtmlonly |
34 | | |
35 | | Definition: |
36 | | =========== |
37 | | |
38 | | SUBROUTINE DLADIV( A, B, C, D, P, Q ) |
39 | | |
40 | | DOUBLE PRECISION A, B, C, D, P, Q |
41 | | |
42 | | |
43 | | > \par Purpose: |
44 | | ============= |
45 | | > |
46 | | > \verbatim |
47 | | > |
48 | | > DLADIV performs complex division in real arithmetic |
49 | | > |
50 | | > a + i*b |
51 | | > p + i*q = --------- |
52 | | > c + i*d |
53 | | > |
54 | | > The algorithm is due to Michael Baudin and Robert L. Smith |
55 | | > and can be found in the paper |
56 | | > "A Robust Complex Division in Scilab" |
57 | | > \endverbatim |
58 | | |
59 | | Arguments: |
60 | | ========== |
61 | | |
62 | | > \param[in] A |
63 | | > \verbatim |
64 | | > A is DOUBLE PRECISION |
65 | | > \endverbatim |
66 | | > |
67 | | > \param[in] B |
68 | | > \verbatim |
69 | | > B is DOUBLE PRECISION |
70 | | > \endverbatim |
71 | | > |
72 | | > \param[in] C |
73 | | > \verbatim |
74 | | > C is DOUBLE PRECISION |
75 | | > \endverbatim |
76 | | > |
77 | | > \param[in] D |
78 | | > \verbatim |
79 | | > D is DOUBLE PRECISION |
80 | | > The scalars a, b, c, and d in the above expression. |
81 | | > \endverbatim |
82 | | > |
83 | | > \param[out] P |
84 | | > \verbatim |
85 | | > P is DOUBLE PRECISION |
86 | | > \endverbatim |
87 | | > |
88 | | > \param[out] Q |
89 | | > \verbatim |
90 | | > Q is DOUBLE PRECISION |
91 | | > The scalars p and q in the above expression. |
92 | | > \endverbatim |
93 | | |
94 | | Authors: |
95 | | ======== |
96 | | |
97 | | > \author Univ. of Tennessee |
98 | | > \author Univ. of California Berkeley |
99 | | > \author Univ. of Colorado Denver |
100 | | > \author NAG Ltd. |
101 | | |
102 | | > \date January 2013 |
103 | | |
104 | | > \ingroup auxOTHERauxiliary |
105 | | |
106 | | ===================================================================== |
107 | | Subroutine */ int igraphdladiv_(doublereal *a, doublereal *b, doublereal *c__, |
108 | | doublereal *d__, doublereal *p, doublereal *q) |
109 | 0 | { |
110 | | /* System generated locals */ |
111 | 0 | doublereal d__1, d__2; |
112 | | |
113 | | /* Local variables */ |
114 | 0 | doublereal s, aa, ab, bb, cc, cd, dd, be, un, ov, eps; |
115 | 0 | extern doublereal igraphdlamch_(char *); |
116 | 0 | extern /* Subroutine */ int dladiv1_(doublereal *, doublereal *, |
117 | 0 | doublereal *, doublereal *, doublereal *, doublereal *); |
118 | | |
119 | | |
120 | | /* -- LAPACK auxiliary routine (version 3.5.0) -- |
121 | | -- LAPACK is a software package provided by Univ. of Tennessee, -- |
122 | | -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- |
123 | | January 2013 |
124 | | |
125 | | |
126 | | ===================================================================== */ |
127 | | |
128 | | |
129 | |
|
130 | 0 | aa = *a; |
131 | 0 | bb = *b; |
132 | 0 | cc = *c__; |
133 | 0 | dd = *d__; |
134 | | /* Computing MAX */ |
135 | 0 | d__1 = abs(*a), d__2 = abs(*b); |
136 | 0 | ab = max(d__1,d__2); |
137 | | /* Computing MAX */ |
138 | 0 | d__1 = abs(*c__), d__2 = abs(*d__); |
139 | 0 | cd = max(d__1,d__2); |
140 | 0 | s = 1.; |
141 | 0 | ov = igraphdlamch_("Overflow threshold"); |
142 | 0 | un = igraphdlamch_("Safe minimum"); |
143 | 0 | eps = igraphdlamch_("Epsilon"); |
144 | 0 | be = 2. / (eps * eps); |
145 | 0 | if (ab >= ov * .5) { |
146 | 0 | aa *= .5; |
147 | 0 | bb *= .5; |
148 | 0 | s *= 2.; |
149 | 0 | } |
150 | 0 | if (cd >= ov * .5) { |
151 | 0 | cc *= .5; |
152 | 0 | dd *= .5; |
153 | 0 | s *= .5; |
154 | 0 | } |
155 | 0 | if (ab <= un * 2. / eps) { |
156 | 0 | aa *= be; |
157 | 0 | bb *= be; |
158 | 0 | s /= be; |
159 | 0 | } |
160 | 0 | if (cd <= un * 2. / eps) { |
161 | 0 | cc *= be; |
162 | 0 | dd *= be; |
163 | 0 | s *= be; |
164 | 0 | } |
165 | 0 | if (abs(*d__) <= abs(*c__)) { |
166 | 0 | dladiv1_(&aa, &bb, &cc, &dd, p, q); |
167 | 0 | } else { |
168 | 0 | dladiv1_(&bb, &aa, &dd, &cc, p, q); |
169 | 0 | *q = -(*q); |
170 | 0 | } |
171 | 0 | *p *= s; |
172 | 0 | *q *= s; |
173 | |
|
174 | 0 | return 0; |
175 | | |
176 | | /* End of DLADIV */ |
177 | |
|
178 | 0 | } /* igraphdladiv_ |
179 | | |
180 | | Subroutine */ int dladiv1_(doublereal *a, doublereal *b, doublereal *c__, |
181 | | doublereal *d__, doublereal *p, doublereal *q) |
182 | 0 | { |
183 | 0 | doublereal r__, t; |
184 | 0 | extern doublereal dladiv2_(doublereal *, doublereal *, doublereal *, |
185 | 0 | doublereal *, doublereal *, doublereal *); |
186 | | |
187 | | |
188 | | /* -- LAPACK auxiliary routine (version 3.5.0) -- |
189 | | -- LAPACK is a software package provided by Univ. of Tennessee, -- |
190 | | -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- |
191 | | January 2013 |
192 | | |
193 | | |
194 | | ===================================================================== */ |
195 | | |
196 | | |
197 | |
|
198 | 0 | r__ = *d__ / *c__; |
199 | 0 | t = 1. / (*c__ + *d__ * r__); |
200 | 0 | *p = dladiv2_(a, b, c__, d__, &r__, &t); |
201 | 0 | *a = -(*a); |
202 | 0 | *q = dladiv2_(b, a, c__, d__, &r__, &t); |
203 | |
|
204 | 0 | return 0; |
205 | | |
206 | | /* End of DLADIV1 */ |
207 | |
|
208 | 0 | } /* dladiv1_ */ |
209 | | |
210 | | doublereal dladiv2_(doublereal *a, doublereal *b, doublereal *c__, doublereal |
211 | | *d__, doublereal *r__, doublereal *t) |
212 | 0 | { |
213 | | /* System generated locals */ |
214 | 0 | doublereal ret_val; |
215 | | |
216 | | /* Local variables */ |
217 | 0 | doublereal br; |
218 | | |
219 | | |
220 | | /* -- LAPACK auxiliary routine (version 3.5.0) -- |
221 | | -- LAPACK is a software package provided by Univ. of Tennessee, -- |
222 | | -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- |
223 | | January 2013 |
224 | | |
225 | | |
226 | | ===================================================================== */ |
227 | | |
228 | | |
229 | |
|
230 | 0 | if (*r__ != 0.) { |
231 | 0 | br = *b * *r__; |
232 | 0 | if (br != 0.) { |
233 | 0 | ret_val = (*a + br) * *t; |
234 | 0 | } else { |
235 | 0 | ret_val = *a * *t + *b * *t * *r__; |
236 | 0 | } |
237 | 0 | } else { |
238 | 0 | ret_val = (*a + *d__ * (*b / *c__)) * *t; |
239 | 0 | } |
240 | |
|
241 | 0 | return ret_val; |
242 | | |
243 | | /* End of DLADIV12 */ |
244 | |
|
245 | 0 | } /* dladiv2_ */ |
246 | | |