[comp.os.vms] possible bug in VMS RTL e**x routine ??

MANAGER@SKIDMORE.BITNET (Leo Geoffrion) (10/21/87)

I believe that I've stumbled onto a bug in the EXP() function
  -- used to calculate e raised to the x power --

We first encountered it when a FORTRAN simulation that ran last
semester now refused to converge on a solution.
After much hacking with the debugger we found incorrect
behavior in the EXP(X) predeclared function in FORTRAN.

In order to check whether the problem might lie in FORTRAN, I
quickly created a test program in Pascal involving the same
EXP(x) function.

Here's the program...
-----------------------------------
TY EXP.PAS

PROGRAM EXP(INPUT,OUTPUT);

VAR   NUM, INIT, END_VALUE,STEP_SIZE,N : REAL;

BEGIN
  WRITE('ENTER INITIAL VALUE ');
  READ(INIT);
  WRITE('ENTER STEP SIZE ');
  READ (STEP_SIZE);
  WRITE('ENTER FINAL VALUE ');
  READ (END_VALUE);
  NUM := INIT;
REPEAT
  BEGIN
   N := EXP(NUM);
  WRITELN (NUM, N );
  NUM := NUM + STEP_SIZE;
  END
UNTIL NUM > END_VALUE;
END.
---------------------------------
Now, when I run it, watch what happens to EXP(-1.168)

---------------------------------
$ RUN EXP
ENTER INITIAL VALUE
-1.180
ENTER STEP SIZE
0.002
ENTER FINAL VALUE
-1.160

-1.18000E+00 3.13683E-01
-1.17800E+00 3.13056E-01
-1.17600E+00 3.12431E-01
-1.17400E+00 3.11807E-01
-1.17200E+00 3.11184E-01
-1.17000E+00 3.10562E-01     <== WHY THE DISCONTINUITY HERE??
-1.16800E+00 3.37994E-01
-1.16600E+00 3.37318E-01
-1.16400E+00 3.36644E-01
-1.16200E+00 3.35972E-01
-1.16000E+00 3.35300E-01

My handy, but primitive, HP calculator confirms that e**-1.168
is *NOT* .338, but rather, .31, which is in logical progression
with the preceding values.

Incidentally, I tried setting all variables to double precision in
order to see if that might solve the problem.   That does not
eliminate the discontinuity -- just does it to more decimal places.

Is it possible that there's a bug in how RTL computes e**x, or
am I just
     a)   hallucinating
     b)   mathematically naive

If a bug, how can we force e**x to return the correct values.  The
discontinuity is just enough to prevent our model from converging
on a value, since the interation is taking place in the vicinity
of x = -1.17.


===================================================================
Leo D. Geoffrion                  BITNET:  MANAGER@SKIDMORE.BITNET
Associate Director for             NYNEX:  (518) 584-5000 Ext. 2628
Academic Computing
Skidmore College
Saratoga Springs, NY  12866