scnrm2.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* scnrm2.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 scnrm2_(integer *n, complex *x, integer *incx)
  14. {
  15. /* System generated locals */
  16. integer i__1, i__2, i__3;
  17. real ret_val, r__1;
  18. /* Builtin functions */
  19. double r_imag(complex *), sqrt(doublereal);
  20. /* Local variables */
  21. integer ix;
  22. real ssq, temp, norm, scale;
  23. /* .. Scalar Arguments .. */
  24. /* .. */
  25. /* .. Array Arguments .. */
  26. /* .. */
  27. /* Purpose */
  28. /* ======= */
  29. /* SCNRM2 returns the euclidean norm of a vector via the function */
  30. /* name, so that */
  31. /* SCNRM2 := sqrt( conjg( x' )*x ) */
  32. /* -- This version written on 25-October-1982. */
  33. /* Modified on 14-October-1993 to inline the call to CLASSQ. */
  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.f;
  46. } else {
  47. scale = 0.f;
  48. ssq = 1.f;
  49. /* The following loop is equivalent to this call to the LAPACK */
  50. /* auxiliary routine: */
  51. /* CALL CLASSQ( 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.f) {
  57. i__3 = ix;
  58. temp = (r__1 = x[i__3].r, dabs(r__1));
  59. if (scale < temp) {
  60. /* Computing 2nd power */
  61. r__1 = scale / temp;
  62. ssq = ssq * (r__1 * r__1) + 1.f;
  63. scale = temp;
  64. } else {
  65. /* Computing 2nd power */
  66. r__1 = temp / scale;
  67. ssq += r__1 * r__1;
  68. }
  69. }
  70. if (r_imag(&x[ix]) != 0.f) {
  71. temp = (r__1 = r_imag(&x[ix]), dabs(r__1));
  72. if (scale < temp) {
  73. /* Computing 2nd power */
  74. r__1 = scale / temp;
  75. ssq = ssq * (r__1 * r__1) + 1.f;
  76. scale = temp;
  77. } else {
  78. /* Computing 2nd power */
  79. r__1 = temp / scale;
  80. ssq += r__1 * r__1;
  81. }
  82. }
  83. /* L10: */
  84. }
  85. norm = scale * sqrt(ssq);
  86. }
  87. ret_val = norm;
  88. return ret_val;
  89. /* End of SCNRM2. */
  90. } /* scnrm2_ */