 LAPACK  3.10.0 LAPACK: Linear Algebra PACKage

 subroutine dladiv ( double precision A, double precision B, double precision C, double precision D, double precision P, double precision Q )

DLADIV performs complex division in real arithmetic, avoiding unnecessary overflow.

Purpose:
DLADIV performs complex division in  real arithmetic

a + i*b
p + i*q = ---------
c + i*d

The algorithm is due to Michael Baudin and Robert L. Smith
and can be found in the paper
"A Robust Complex Division in Scilab"
Parameters
 [in] A A is DOUBLE PRECISION [in] B B is DOUBLE PRECISION [in] C C is DOUBLE PRECISION [in] D D is DOUBLE PRECISION The scalars a, b, c, and d in the above expression. [out] P P is DOUBLE PRECISION [out] Q Q is DOUBLE PRECISION The scalars p and q in the above expression.

Definition at line 90 of file dladiv.f.

91 *
92 * -- LAPACK auxiliary routine --
93 * -- LAPACK is a software package provided by Univ. of Tennessee, --
94 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
95 *
96 * .. Scalar Arguments ..
97  DOUBLE PRECISION A, B, C, D, P, Q
98 * ..
99 *
100 * =====================================================================
101 *
102 * .. Parameters ..
103  DOUBLE PRECISION BS
104  parameter( bs = 2.0d0 )
105  DOUBLE PRECISION HALF
106  parameter( half = 0.5d0 )
107  DOUBLE PRECISION TWO
108  parameter( two = 2.0d0 )
109 *
110 * .. Local Scalars ..
111  DOUBLE PRECISION AA, BB, CC, DD, AB, CD, S, OV, UN, BE, EPS
112 * ..
113 * .. External Functions ..
114  DOUBLE PRECISION DLAMCH
115  EXTERNAL dlamch
116 * ..
117 * .. External Subroutines ..
119 * ..
120 * .. Intrinsic Functions ..
121  INTRINSIC abs, max
122 * ..
123 * .. Executable Statements ..
124 *
125  aa = a
126  bb = b
127  cc = c
128  dd = d
129  ab = max( abs(a), abs(b) )
130  cd = max( abs(c), abs(d) )
131  s = 1.0d0
132
133  ov = dlamch( 'Overflow threshold' )
134  un = dlamch( 'Safe minimum' )
135  eps = dlamch( 'Epsilon' )
136  be = bs / (eps*eps)
137
138  IF( ab >= half*ov ) THEN
139  aa = half * aa
140  bb = half * bb
141  s = two * s
142  END IF
143  IF( cd >= half*ov ) THEN
144  cc = half * cc
145  dd = half * dd
146  s = half * s
147  END IF
148  IF( ab <= un*bs/eps ) THEN
149  aa = aa * be
150  bb = bb * be
151  s = s / be
152  END IF
153  IF( cd <= un*bs/eps ) THEN
154  cc = cc * be
155  dd = dd * be
156  s = s * be
157  END IF
158  IF( abs( d ).LE.abs( c ) ) THEN
159  CALL dladiv1(aa, bb, cc, dd, p, q)
160  ELSE
161  CALL dladiv1(bb, aa, dd, cc, p, q)
162  q = -q
163  END IF
164  p = p * s
165  q = q * s
166 *
167  RETURN
168 *