      REAL FUNCTION PYTHAG(A,B)
C
C     FINDS SQRT(A**2+B**2) WITHOUT OVERFLOW OR DESTRUCTIVE UNDERFLOW
C
C     .. Scalar Arguments ..
      REAL A, B
C     .. Local Scalars ..
      REAL P, R, S, T, U
C     .. Intrinsic Functions ..
      INTRINSIC                        ABS, MAX, MIN
C     .. Executable Statements ..
      P = MAX(ABS(A),ABS(B))
      IF (P.EQ.0.0E0) GO TO 40
      R = (MIN(ABS(A),ABS(B))/P)**2
   20 CONTINUE
      T = 4.0E0 + R
      IF (T.EQ.4.0E0) GO TO 40
      S = R/T
      U = 1.0E0 + 2.0E0*S
      P = U*P
      R = (S/U)**2*R
      GO TO 20
   40 PYTHAG = P
      RETURN
      END
