#include "fpreproc/library_names.h"
#include "fpreproc/fp_const.h"
*DECK DEXPRL
      REAL*8 FUNCTION DEXPRL (X)
C***BEGIN PROLOGUE  DEXPRL
C***PURPOSE  Calculate the relative error exponential (EXP(X)-1)/X.
C***LIBRARY   SLATEC (FNLIB)
C***CATEGORY  C4B
C***TYPE      REAL*8 (EXPREL-S, DEXPRL-D, CEXPRL-C)
C***KEYWORDS  ELEMENTARY FUNCTIONS, EXPONENTIAL, FIRST ORDER, FNLIB
C***AUTHOR  Fullerton, W., (LANL)
C***DESCRIPTION
C
C Evaluate  EXPREL(X) = (EXP(X) - 1.0) / X.   For small ABS(X) the
C Taylor series is used.  If X is negative the reflection formula
C         EXPREL(X) = EXP(X) * EXPREL(ABS(X))
C may be used.  This reflection formula will be of use when the
C evaluation for small ABS(X) is done by Chebyshev series rather than
C Taylor series.
C
C***REFERENCES  (NONE)
C***ROUTINES CALLED  D1MACH
C***REVISION HISTORY  (YYMMDD)
C   770801  DATE WRITTEN
C   890531  Changed all specific intrinsics to generic.  (WRB)
C   890911  Removed unnecessary intrinsics.  (WRB)
C   890911  REVISION DATE from Version 3.2
C   891214  Prologue converted to Version 4.0 format.  (BAB)
C***END PROLOGUE  DEXPRL
C============
C idecl:  explicitize implicit INTEGER declarations:
      IMPLICIT NONE
      INTEGER nterms,i
C============
      REAL*8 X, ABSX, ALNEPS, XBND, XLN, XN,  D1MACH
      LOGICAL FIRST
      SAVE NTERMS, XBND, FIRST
      DATA FIRST /.TRUE./
C***FIRST EXECUTABLE STATEMENT  DEXPRL
      IF (FIRST) THEN
         ALNEPS = LOG(D1MACH(3))
         XN = CONST(3.72,0)- CONST(0.3,0)*ALNEPS
         XLN = LOG((XN+CONST(1.0,0))/CONST(1.36,0))
         NTERMS = XN - (XN*XLN+ALNEPS)/(XLN+CONST(1.36,0)) +
     >      CONST(1.5,0)
         XBND = D1MACH(3)
      ENDIF
      FIRST = .FALSE.
C
      ABSX = ABS(X)
      IF (ABSX.GT.CONST(0.5,0)) DEXPRL = (EXP(X)-CONST(1.0,0))/X
      IF (ABSX.GT.CONST(0.5,0)) RETURN
C
      DEXPRL = CONST(1.0,0)
      IF (ABSX.LT.XBND) RETURN
C
      DEXPRL = CONST(0.0,0)
      DO 20 I=1,NTERMS
        DEXPRL = CONST(1.0,0)+ DEXPRL*X/(NTERMS+2-I)
 20   CONTINUE
C
      RETURN
      END
! 22Jun2000 fgtok -s r8_precision.sub "r8con.csh conversion"
! 22Jun2000 fgtok
! 22Jun2000 fgtok
