dznrm2.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* dznrm2.f -- translated by f2c (version 20061008).
  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. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. doublereal dznrm2_(integer *n, doublecomplex *x, integer *incx)
  14. {
  15. /* System generated locals */
  16. integer i__1, i__2, i__3;
  17. doublereal ret_val, d__1;
  18. /* Builtin functions */
  19. double d_imag(doublecomplex *), sqrt(doublereal);
  20. /* Local variables */
  21. integer ix;
  22. doublereal ssq, temp, norm, scale;
  23. /* .. Scalar Arguments .. */
  24. /* .. */
  25. /* .. Array Arguments .. */
  26. /* .. */
  27. /* Purpose */
  28. /* ======= */
  29. /* DZNRM2 returns the euclidean norm of a vector via the function */
  30. /* name, so that */
  31. /* DZNRM2 := sqrt( conjg( x' )*x ) */
  32. /* -- This version written on 25-October-1982. */
  33. /* Modified on 14-October-1993 to inline the call to ZLASSQ. */
  34. /* Sven Hammarling, Nag Ltd. */
  35. /* .. Parameters .. */
  36. /* .. */
  37. /* .. Local Scalars .. */
  38. /* .. */
  39. /* .. Intrinsic Functions .. */
  40. /* .. */
  41. /* Parameter adjustments */
  42. --x;
  43. /* Function Body */
  44. if (*n < 1 || *incx < 1) {
  45. norm = 0.;
  46. } else {
  47. scale = 0.;
  48. ssq = 1.;
  49. /* The following loop is equivalent to this call to the LAPACK */
  50. /* auxiliary routine: */
  51. /* CALL ZLASSQ( N, X, INCX, SCALE, SSQ ) */
  52. i__1 = (*n - 1) * *incx + 1;
  53. i__2 = *incx;
  54. for (ix = 1; i__2 < 0 ? ix >= i__1 : ix <= i__1; ix += i__2) {
  55. i__3 = ix;
  56. if (x[i__3].r != 0.) {
  57. i__3 = ix;
  58. temp = (d__1 = x[i__3].r, abs(d__1));
  59. if (scale < temp) {
  60. /* Computing 2nd power */
  61. d__1 = scale / temp;
  62. ssq = ssq * (d__1 * d__1) + 1.;
  63. scale = temp;
  64. } else {
  65. /* Computing 2nd power */
  66. d__1 = temp / scale;
  67. ssq += d__1 * d__1;
  68. }
  69. }
  70. if (d_imag(&x[ix]) != 0.) {
  71. temp = (d__1 = d_imag(&x[ix]), abs(d__1));
  72. if (scale < temp) {
  73. /* Computing 2nd power */
  74. d__1 = scale / temp;
  75. ssq = ssq * (d__1 * d__1) + 1.;
  76. scale = temp;
  77. } else {
  78. /* Computing 2nd power */
  79. d__1 = temp / scale;
  80. ssq += d__1 * d__1;
  81. }
  82. }
  83. /* L10: */
  84. }
  85. norm = scale * sqrt(ssq);
  86. }
  87. ret_val = norm;
  88. return ret_val;
  89. /* End of DZNRM2. */
  90. } /* dznrm2_ */