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.

zrscl.f 6.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. *> \brief \b ZDRSCL multiplies a vector by the reciprocal of a real scalar.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download ZDRSCL + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zdrscl.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zdrscl.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zdrscl.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZRSCL( N, A, X, INCX )
  22. *
  23. * .. Scalar Arguments ..
  24. * INTEGER INCX, N
  25. * COMPLEX*16 A
  26. * ..
  27. * .. Array Arguments ..
  28. * COMPLEX*16 X( * )
  29. * ..
  30. *
  31. *
  32. *> \par Purpose:
  33. * =============
  34. *>
  35. *> \verbatim
  36. *>
  37. *> ZRSCL multiplies an n-element complex vector x by the complex scalar
  38. *> 1/a. This is done without overflow or underflow as long as
  39. *> the final result x/a does not overflow or underflow.
  40. *> \endverbatim
  41. *
  42. * Arguments:
  43. * ==========
  44. *
  45. *> \param[in] N
  46. *> \verbatim
  47. *> N is INTEGER
  48. *> The number of components of the vector x.
  49. *> \endverbatim
  50. *>
  51. *> \param[in] A
  52. *> \verbatim
  53. *> A is COMPLEX*16
  54. *> The scalar a which is used to divide each component of x.
  55. *> A must not be 0, or the subroutine will divide by zero.
  56. *> \endverbatim
  57. *>
  58. *> \param[in,out] X
  59. *> \verbatim
  60. *> X is COMPLEX*16 array, dimension
  61. *> (1+(N-1)*abs(INCX))
  62. *> The n-element vector x.
  63. *> \endverbatim
  64. *>
  65. *> \param[in] INCX
  66. *> \verbatim
  67. *> INCX is INTEGER
  68. *> The increment between successive values of the vector SX.
  69. *> > 0: SX(1) = X(1) and SX(1+(i-1)*INCX) = x(i), 1< i<= n
  70. *> \endverbatim
  71. *
  72. * Authors:
  73. * ========
  74. *
  75. *> \author Univ. of Tennessee
  76. *> \author Univ. of California Berkeley
  77. *> \author Univ. of Colorado Denver
  78. *> \author NAG Ltd.
  79. *
  80. *> \ingroup complex16OTHERauxiliary
  81. *
  82. * =====================================================================
  83. SUBROUTINE ZRSCL( N, A, X, INCX )
  84. *
  85. * -- LAPACK auxiliary routine --
  86. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  87. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  88. *
  89. * .. Scalar Arguments ..
  90. INTEGER INCX, N
  91. COMPLEX*16 A
  92. * ..
  93. * .. Array Arguments ..
  94. COMPLEX*16 X( * )
  95. * ..
  96. *
  97. * =====================================================================
  98. *
  99. * .. Parameters ..
  100. DOUBLE PRECISION ZERO, ONE
  101. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  102. * ..
  103. * .. Local Scalars ..
  104. DOUBLE PRECISION SAFMAX, SAFMIN, OV, AR, AI, ABSR, ABSI, UR, UI
  105. * ..
  106. * .. External Functions ..
  107. DOUBLE PRECISION DLAMCH
  108. COMPLEX*16 ZLADIV
  109. EXTERNAL DLAMCH, ZLADIV
  110. * ..
  111. * .. External Subroutines ..
  112. EXTERNAL DSCAL, ZDSCAL, ZDRSCL
  113. * ..
  114. * .. Intrinsic Functions ..
  115. INTRINSIC ABS
  116. * ..
  117. * .. Executable Statements ..
  118. *
  119. * Quick return if possible
  120. *
  121. IF( N.LE.0 )
  122. $ RETURN
  123. *
  124. * Get machine parameters
  125. *
  126. SAFMIN = DLAMCH( 'S' )
  127. SAFMAX = ONE / SAFMIN
  128. OV = DLAMCH( 'O' )
  129. *
  130. * Initialize constants related to A.
  131. *
  132. AR = DBLE( A )
  133. AI = DIMAG( A )
  134. ABSR = ABS( AR )
  135. ABSI = ABS( AI )
  136. *
  137. IF( AI.EQ.ZERO ) THEN
  138. * If alpha is real, then we can use csrscl
  139. CALL ZDRSCL( N, AR, X, INCX )
  140. *
  141. ELSE IF( AR.EQ.ZERO ) THEN
  142. * If alpha has a zero real part, then we follow the same rules as if
  143. * alpha were real.
  144. IF( ABSI.GT.SAFMAX ) THEN
  145. CALL ZDSCAL( N, SAFMIN, X, INCX )
  146. CALL ZSCAL( N, DCMPLX( ZERO, -SAFMAX / AI ), X, INCX )
  147. ELSE IF( ABSI.LT.SAFMIN ) THEN
  148. CALL ZSCAL( N, DCMPLX( ZERO, -SAFMIN / AI ), X, INCX )
  149. CALL ZDSCAL( N, SAFMAX, X, INCX )
  150. ELSE
  151. CALL ZSCAL( N, DCMPLX( ZERO, -ONE / AI ), X, INCX )
  152. END IF
  153. *
  154. ELSE
  155. * The following numbers can be computed.
  156. * They are the inverse of the real and imaginary parts of 1/alpha.
  157. * Note that a and b are always different from zero.
  158. * NaNs are only possible if either:
  159. * 1. alphaR or alphaI is NaN.
  160. * 2. alphaR and alphaI are both infinite, in which case it makes sense
  161. * to propagate a NaN.
  162. UR = AR + AI * ( AI / AR )
  163. UI = AI + AR * ( AR / AI )
  164. *
  165. IF( (ABS( UR ).LT.SAFMIN).OR.(ABS( UI ).LT.SAFMIN) ) THEN
  166. * This means that both alphaR and alphaI are very small.
  167. CALL ZSCAL( N, DCMPLX( SAFMIN / UR, -SAFMIN / UI ), X,
  168. $ INCX )
  169. CALL ZDSCAL( N, SAFMAX, X, INCX )
  170. ELSE IF( (ABS( UR ).GT.SAFMAX).OR.(ABS( UI ).GT.SAFMAX) ) THEN
  171. IF( (ABSR.GT.OV).OR.(ABSI.GT.OV) ) THEN
  172. * This means that a and b are both Inf. No need for scaling.
  173. CALL ZSCAL( N, DCMPLX( ONE / UR, -ONE / UI ), X, INCX )
  174. ELSE
  175. CALL ZDSCAL( N, SAFMIN, X, INCX )
  176. IF( (ABS( UR ).GT.OV).OR.(ABS( UI ).GT.OV) ) THEN
  177. * Infs were generated. We do proper scaling to avoid them.
  178. IF( ABSR.GE.ABSI ) THEN
  179. * ABS( UR ) <= ABS( UI )
  180. UR = (SAFMIN * AR) + SAFMIN * (AI * ( AI / AR ))
  181. UI = (SAFMIN * AI) + AR * ( (SAFMIN * AR) / AI )
  182. ELSE
  183. * ABS( UR ) > ABS( UI )
  184. UR = (SAFMIN * AR) + AI * ( (SAFMIN * AI) / AR )
  185. UI = (SAFMIN * AI) + SAFMIN * (AR * ( AR / AI ))
  186. END IF
  187. CALL ZSCAL( N, DCMPLX( ONE / UR, -ONE / UI ), X,
  188. $ INCX )
  189. ELSE
  190. CALL ZSCAL( N, DCMPLX( SAFMAX / UR, -SAFMAX / UI ),
  191. $ X, INCX )
  192. END IF
  193. END IF
  194. ELSE
  195. CALL ZSCAL( N, DCMPLX( ONE / UR, -ONE / UI ), X, INCX )
  196. END IF
  197. END IF
  198. *
  199. RETURN
  200. *
  201. * End of ZRSCL
  202. *
  203. END