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 5.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. *> \ingroup realOTHERauxiliary
  88. *
  89. * =====================================================================
  90. SUBROUTINE SLADIV( A, B, C, D, P, Q )
  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. REAL A, B, C, D, P, Q
  98. * ..
  99. *
  100. * =====================================================================
  101. *
  102. * .. Parameters ..
  103. REAL BS
  104. PARAMETER ( BS = 2.0E0 )
  105. REAL HALF
  106. PARAMETER ( HALF = 0.5E0 )
  107. REAL TWO
  108. PARAMETER ( TWO = 2.0E0 )
  109. *
  110. * .. Local Scalars ..
  111. REAL AA, BB, CC, DD, AB, CD, S, OV, UN, BE, EPS
  112. * ..
  113. * .. External Functions ..
  114. REAL SLAMCH
  115. EXTERNAL SLAMCH
  116. * ..
  117. * .. External Subroutines ..
  118. EXTERNAL SLADIV1
  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.0E0
  132. OV = SLAMCH( 'Overflow threshold' )
  133. UN = SLAMCH( 'Safe minimum' )
  134. EPS = SLAMCH( 'Epsilon' )
  135. BE = BS / (EPS*EPS)
  136. IF( AB >= HALF*OV ) THEN
  137. AA = HALF * AA
  138. BB = HALF * BB
  139. S = TWO * S
  140. END IF
  141. IF( CD >= HALF*OV ) THEN
  142. CC = HALF * CC
  143. DD = HALF * DD
  144. S = HALF * S
  145. END IF
  146. IF( AB <= UN*BS/EPS ) THEN
  147. AA = AA * BE
  148. BB = BB * BE
  149. S = S / BE
  150. END IF
  151. IF( CD <= UN*BS/EPS ) THEN
  152. CC = CC * BE
  153. DD = DD * BE
  154. S = S * BE
  155. END IF
  156. IF( ABS( D ).LE.ABS( C ) ) THEN
  157. CALL SLADIV1(AA, BB, CC, DD, P, Q)
  158. ELSE
  159. CALL SLADIV1(BB, AA, DD, CC, P, Q)
  160. Q = -Q
  161. END IF
  162. P = P * S
  163. Q = Q * S
  164. *
  165. RETURN
  166. *
  167. * End of SLADIV
  168. *
  169. END
  170. *> \ingroup realOTHERauxiliary
  171. SUBROUTINE SLADIV1( A, B, C, D, P, Q )
  172. *
  173. * -- LAPACK auxiliary routine --
  174. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  175. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  176. *
  177. * .. Scalar Arguments ..
  178. REAL A, B, C, D, P, Q
  179. * ..
  180. *
  181. * =====================================================================
  182. *
  183. * .. Parameters ..
  184. REAL ONE
  185. PARAMETER ( ONE = 1.0E0 )
  186. *
  187. * .. Local Scalars ..
  188. REAL R, T
  189. * ..
  190. * .. External Functions ..
  191. REAL SLADIV2
  192. EXTERNAL SLADIV2
  193. * ..
  194. * .. Executable Statements ..
  195. *
  196. R = D / C
  197. T = ONE / (C + D * R)
  198. P = SLADIV2(A, B, C, D, R, T)
  199. A = -A
  200. Q = SLADIV2(B, A, C, D, R, T)
  201. *
  202. RETURN
  203. *
  204. * End of SLADIV1
  205. *
  206. END
  207. *> \ingroup realOTHERauxiliary
  208. REAL FUNCTION SLADIV2( A, B, C, D, R, T )
  209. *
  210. * -- LAPACK auxiliary routine --
  211. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  212. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  213. *
  214. * .. Scalar Arguments ..
  215. REAL A, B, C, D, R, T
  216. * ..
  217. *
  218. * =====================================================================
  219. *
  220. * .. Parameters ..
  221. REAL ZERO
  222. PARAMETER ( ZERO = 0.0E0 )
  223. *
  224. * .. Local Scalars ..
  225. REAL BR
  226. * ..
  227. * .. Executable Statements ..
  228. *
  229. IF( R.NE.ZERO ) THEN
  230. BR = B * R
  231. if( BR.NE.ZERO ) THEN
  232. SLADIV2 = (A + BR) * T
  233. ELSE
  234. SLADIV2 = A * T + (B * T) * R
  235. END IF
  236. ELSE
  237. SLADIV2 = (A + D * (B / C)) * T
  238. END IF
  239. *
  240. RETURN
  241. *
  242. * End of SLADIV2
  243. *
  244. END