You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sladiv.f 6.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. *> \brief \b SLADIV performs complex division in real arithmetic, avoiding unnecessary overflow.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SLADIV + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sladiv.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sladiv.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sladiv.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SLADIV( A, B, C, D, P, Q )
  22. *
  23. * .. Scalar Arguments ..
  24. * REAL A, B, C, D, P, Q
  25. * ..
  26. *
  27. *
  28. *> \par Purpose:
  29. * =============
  30. *>
  31. *> \verbatim
  32. *>
  33. *> SLADIV performs complex division in real arithmetic
  34. *>
  35. *> a + i*b
  36. *> p + i*q = ---------
  37. *> c + i*d
  38. *>
  39. *> The algorithm is due to Michael Baudin and Robert L. Smith
  40. *> and can be found in the paper
  41. *> "A Robust Complex Division in Scilab"
  42. *> \endverbatim
  43. *
  44. * Arguments:
  45. * ==========
  46. *
  47. *> \param[in] A
  48. *> \verbatim
  49. *> A is REAL
  50. *> \endverbatim
  51. *>
  52. *> \param[in] B
  53. *> \verbatim
  54. *> B is REAL
  55. *> \endverbatim
  56. *>
  57. *> \param[in] C
  58. *> \verbatim
  59. *> C is REAL
  60. *> \endverbatim
  61. *>
  62. *> \param[in] D
  63. *> \verbatim
  64. *> D is REAL
  65. *> The scalars a, b, c, and d in the above expression.
  66. *> \endverbatim
  67. *>
  68. *> \param[out] P
  69. *> \verbatim
  70. *> P is REAL
  71. *> \endverbatim
  72. *>
  73. *> \param[out] Q
  74. *> \verbatim
  75. *> Q is REAL
  76. *> The scalars p and q in the above expression.
  77. *> \endverbatim
  78. *
  79. * Authors:
  80. * ========
  81. *
  82. *> \author Univ. of Tennessee
  83. *> \author Univ. of California Berkeley
  84. *> \author Univ. of Colorado Denver
  85. *> \author NAG Ltd.
  86. *
  87. *> \date January 2013
  88. *
  89. *> \ingroup realOTHERauxiliary
  90. *
  91. * =====================================================================
  92. SUBROUTINE SLADIV( A, B, C, D, P, Q )
  93. *
  94. * -- LAPACK auxiliary routine (version 3.7.0) --
  95. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  96. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  97. * January 2013
  98. *
  99. * .. Scalar Arguments ..
  100. REAL A, B, C, D, P, Q
  101. * ..
  102. *
  103. * =====================================================================
  104. *
  105. * .. Parameters ..
  106. REAL BS
  107. PARAMETER ( BS = 2.0E0 )
  108. REAL HALF
  109. PARAMETER ( HALF = 0.5E0 )
  110. REAL TWO
  111. PARAMETER ( TWO = 2.0E0 )
  112. *
  113. * .. Local Scalars ..
  114. REAL AA, BB, CC, DD, AB, CD, S, OV, UN, BE, EPS
  115. * ..
  116. * .. External Functions ..
  117. REAL SLAMCH
  118. EXTERNAL SLAMCH
  119. * ..
  120. * .. External Subroutines ..
  121. EXTERNAL SLADIV1
  122. * ..
  123. * .. Intrinsic Functions ..
  124. INTRINSIC ABS, MAX
  125. * ..
  126. * .. Executable Statements ..
  127. *
  128. AA = A
  129. BB = B
  130. CC = C
  131. DD = D
  132. AB = MAX( ABS(A), ABS(B) )
  133. CD = MAX( ABS(C), ABS(D) )
  134. S = 1.0E0
  135. OV = SLAMCH( 'Overflow threshold' )
  136. UN = SLAMCH( 'Safe minimum' )
  137. EPS = SLAMCH( 'Epsilon' )
  138. BE = BS / (EPS*EPS)
  139. IF( AB >= HALF*OV ) THEN
  140. AA = HALF * AA
  141. BB = HALF * BB
  142. S = TWO * S
  143. END IF
  144. IF( CD >= HALF*OV ) THEN
  145. CC = HALF * CC
  146. DD = HALF * DD
  147. S = HALF * S
  148. END IF
  149. IF( AB <= UN*BS/EPS ) THEN
  150. AA = AA * BE
  151. BB = BB * BE
  152. S = S / BE
  153. END IF
  154. IF( CD <= UN*BS/EPS ) THEN
  155. CC = CC * BE
  156. DD = DD * BE
  157. S = S * BE
  158. END IF
  159. IF( ABS( D ).LE.ABS( C ) ) THEN
  160. CALL SLADIV1(AA, BB, CC, DD, P, Q)
  161. ELSE
  162. CALL SLADIV1(BB, AA, DD, CC, P, Q)
  163. Q = -Q
  164. END IF
  165. P = P * S
  166. Q = Q * S
  167. *
  168. RETURN
  169. *
  170. * End of SLADIV
  171. *
  172. END
  173. *> \ingroup realOTHERauxiliary
  174. SUBROUTINE SLADIV1( A, B, C, D, P, Q )
  175. *
  176. * -- LAPACK auxiliary routine (version 3.7.0) --
  177. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  178. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  179. * January 2013
  180. *
  181. * .. Scalar Arguments ..
  182. REAL A, B, C, D, P, Q
  183. * ..
  184. *
  185. * =====================================================================
  186. *
  187. * .. Parameters ..
  188. REAL ONE
  189. PARAMETER ( ONE = 1.0E0 )
  190. *
  191. * .. Local Scalars ..
  192. REAL R, T
  193. * ..
  194. * .. External Functions ..
  195. REAL SLADIV2
  196. EXTERNAL SLADIV2
  197. * ..
  198. * .. Executable Statements ..
  199. *
  200. R = D / C
  201. T = ONE / (C + D * R)
  202. P = SLADIV2(A, B, C, D, R, T)
  203. A = -A
  204. Q = SLADIV2(B, A, C, D, R, T)
  205. *
  206. RETURN
  207. *
  208. * End of SLADIV1
  209. *
  210. END
  211. *> \ingroup realOTHERauxiliary
  212. REAL FUNCTION SLADIV2( A, B, C, D, R, T )
  213. *
  214. * -- LAPACK auxiliary routine (version 3.7.0) --
  215. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  216. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  217. * January 2013
  218. *
  219. * .. Scalar Arguments ..
  220. REAL A, B, C, D, R, T
  221. * ..
  222. *
  223. * =====================================================================
  224. *
  225. * .. Parameters ..
  226. REAL ZERO
  227. PARAMETER ( ZERO = 0.0E0 )
  228. *
  229. * .. Local Scalars ..
  230. REAL BR
  231. * ..
  232. * .. Executable Statements ..
  233. *
  234. IF( R.NE.ZERO ) THEN
  235. BR = B * R
  236. if( BR.NE.ZERO ) THEN
  237. SLADIV2 = (A + BR) * T
  238. ELSE
  239. SLADIV2 = A * T + (B * T) * R
  240. END IF
  241. ELSE
  242. SLADIV2 = (A + D * (B / C)) * T
  243. END IF
  244. *
  245. RETURN
  246. *
  247. * End of SLADIV
  248. *
  249. END