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.

snrm2.f 2.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. *> \brief \b SNRM2
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * REAL FUNCTION SNRM2(N,X,INCX)
  12. *
  13. * .. Scalar Arguments ..
  14. * INTEGER INCX,N
  15. * ..
  16. * .. Array Arguments ..
  17. * REAL X(*)
  18. * ..
  19. *
  20. *
  21. *> \par Purpose:
  22. * =============
  23. *>
  24. *> \verbatim
  25. *>
  26. *> SNRM2 returns the euclidean norm of a vector via the function
  27. *> name, so that
  28. *>
  29. *> SNRM2 := sqrt( x'*x ).
  30. *> \endverbatim
  31. *
  32. * Authors:
  33. * ========
  34. *
  35. *> \author Univ. of Tennessee
  36. *> \author Univ. of California Berkeley
  37. *> \author Univ. of Colorado Denver
  38. *> \author NAG Ltd.
  39. *
  40. *> \date November 2011
  41. *
  42. *> \ingroup single_blas_level1
  43. *
  44. *> \par Further Details:
  45. * =====================
  46. *>
  47. *> \verbatim
  48. *>
  49. *> -- This version written on 25-October-1982.
  50. *> Modified on 14-October-1993 to inline the call to SLASSQ.
  51. *> Sven Hammarling, Nag Ltd.
  52. *> \endverbatim
  53. *>
  54. * =====================================================================
  55. REAL FUNCTION SNRM2(N,X,INCX)
  56. *
  57. * -- Reference BLAS level1 routine (version 3.4.0) --
  58. * -- Reference BLAS is a software package provided by Univ. of Tennessee, --
  59. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  60. * November 2011
  61. *
  62. * .. Scalar Arguments ..
  63. INTEGER INCX,N
  64. * ..
  65. * .. Array Arguments ..
  66. REAL X(*)
  67. * ..
  68. *
  69. * =====================================================================
  70. *
  71. * .. Parameters ..
  72. REAL ONE,ZERO
  73. PARAMETER (ONE=1.0E+0,ZERO=0.0E+0)
  74. * ..
  75. * .. Local Scalars ..
  76. REAL ABSXI,NORM,SCALE,SSQ
  77. INTEGER IX
  78. * ..
  79. * .. Intrinsic Functions ..
  80. INTRINSIC ABS,SQRT
  81. * ..
  82. IF (N.LT.1 .OR. INCX.LT.1) THEN
  83. NORM = ZERO
  84. ELSE IF (N.EQ.1) THEN
  85. NORM = ABS(X(1))
  86. ELSE
  87. SCALE = ZERO
  88. SSQ = ONE
  89. * The following loop is equivalent to this call to the LAPACK
  90. * auxiliary routine:
  91. * CALL SLASSQ( N, X, INCX, SCALE, SSQ )
  92. *
  93. DO 10 IX = 1,1 + (N-1)*INCX,INCX
  94. IF (X(IX).NE.ZERO) THEN
  95. ABSXI = ABS(X(IX))
  96. IF (SCALE.LT.ABSXI) THEN
  97. SSQ = ONE + SSQ* (SCALE/ABSXI)**2
  98. SCALE = ABSXI
  99. ELSE
  100. SSQ = SSQ + (ABSXI/SCALE)**2
  101. END IF
  102. END IF
  103. 10 CONTINUE
  104. NORM = SCALE*SQRT(SSQ)
  105. END IF
  106. *
  107. SNRM2 = NORM
  108. RETURN
  109. *
  110. * End of SNRM2.
  111. *
  112. END