dnrm2.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* dnrm2.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 dnrm2_(integer *n, doublereal *x, integer *incx)
  14. {
  15. /* System generated locals */
  16. integer i__1, i__2;
  17. doublereal ret_val, d__1;
  18. /* Builtin functions */
  19. double sqrt(doublereal);
  20. /* Local variables */
  21. integer ix;
  22. doublereal ssq, norm, scale, absxi;
  23. /* .. Scalar Arguments .. */
  24. /* .. */
  25. /* .. Array Arguments .. */
  26. /* .. */
  27. /* Purpose */
  28. /* ======= */
  29. /* DNRM2 returns the euclidean norm of a vector via the function */
  30. /* name, so that */
  31. /* DNRM2 := sqrt( x'*x ) */
  32. /* -- This version written on 25-October-1982. */
  33. /* Modified on 14-October-1993 to inline the call to DLASSQ. */
  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 if (*n == 1) {
  47. norm = abs(x[1]);
  48. } else {
  49. scale = 0.;
  50. ssq = 1.;
  51. /* The following loop is equivalent to this call to the LAPACK */
  52. /* auxiliary routine: */
  53. /* CALL DLASSQ( N, X, INCX, SCALE, SSQ ) */
  54. i__1 = (*n - 1) * *incx + 1;
  55. i__2 = *incx;
  56. for (ix = 1; i__2 < 0 ? ix >= i__1 : ix <= i__1; ix += i__2) {
  57. if (x[ix] != 0.) {
  58. absxi = (d__1 = x[ix], abs(d__1));
  59. if (scale < absxi) {
  60. /* Computing 2nd power */
  61. d__1 = scale / absxi;
  62. ssq = ssq * (d__1 * d__1) + 1.;
  63. scale = absxi;
  64. } else {
  65. /* Computing 2nd power */
  66. d__1 = absxi / scale;
  67. ssq += d__1 * d__1;
  68. }
  69. }
  70. /* L10: */
  71. }
  72. norm = scale * sqrt(ssq);
  73. }
  74. ret_val = norm;
  75. return ret_val;
  76. /* End of DNRM2. */
  77. } /* dnrm2_ */