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.

snrm2f.f 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. REAL FUNCTION SNRM2F ( N, X, INCX )
  2. * .. Scalar Arguments ..
  3. INTEGER INCX, N
  4. * .. Array Arguments ..
  5. REAL X( * )
  6. * ..
  7. *
  8. * SNRM2 returns the euclidean norm of a vector via the function
  9. * name, so that
  10. *
  11. * SNRM2 := sqrt( x'*x )
  12. *
  13. *
  14. *
  15. * -- This version written on 25-October-1982.
  16. * Modified on 14-October-1993 to inline the call to SLASSQ.
  17. * Sven Hammarling, Nag Ltd.
  18. *
  19. *
  20. * .. Parameters ..
  21. REAL ONE , ZERO
  22. PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
  23. * .. Local Scalars ..
  24. INTEGER IX
  25. REAL ABSXI, NORM, SCALE, SSQ
  26. * .. Intrinsic Functions ..
  27. INTRINSIC ABS, SQRT
  28. * ..
  29. * .. Executable Statements ..
  30. IF( N.LT.1 .OR. INCX.LT.1 )THEN
  31. NORM = ZERO
  32. ELSE IF( N.EQ.1 )THEN
  33. NORM = ABS( X( 1 ) )
  34. ELSE
  35. SCALE = ZERO
  36. SSQ = ONE
  37. * The following loop is equivalent to this call to the LAPACK
  38. * auxiliary routine:
  39. * CALL SLASSQ( N, X, INCX, SCALE, SSQ )
  40. *
  41. DO 10, IX = 1, 1 + ( N - 1 )*INCX, INCX
  42. IF( X( IX ).NE.ZERO )THEN
  43. ABSXI = ABS( X( IX ) )
  44. IF( SCALE.LT.ABSXI )THEN
  45. SSQ = ONE + SSQ*( SCALE/ABSXI )**2
  46. SCALE = ABSXI
  47. ELSE
  48. SSQ = SSQ + ( ABSXI/SCALE )**2
  49. END IF
  50. END IF
  51. 10 CONTINUE
  52. NORM = SCALE * SQRT( SSQ )
  53. END IF
  54. *
  55. SNRM2F = NORM
  56. RETURN
  57. *
  58. * End of SNRM2.
  59. *
  60. END