Bug in tanh?



-----maxima-bounces at math.utexas.edu wrote: -----

>I suspect it is sufficient to compute
>Tanh = 2/(exp(-2*x)+1)  -1

In trigi.lisp cvs r 1.9, we had

(defmfun tanh (num)
   (let ((yy (float num)) (yflo 0.0))
     (cond ((< (abs yy) #.(sqrt +eps+)) yy)
   (t (setq yflo (exp (*$ -2.0 (abs yy))) yflo (//$ (1-$ yflo) (1+$ yflo)))
      (if (plusp yy) (-$ yflo) yflo)))))

This code doesn't overflow for large inputs, but its accuracy is poor
for inputs near 0. The old code needed a *great* deal of work (I think
some of it didn't work for complex double floats, for example).

I was largely responsible for the move toward turning over most double
float
evaluation for trig-like functions to CL (we all did debate the change on
the list).
If there is a well-tested CL  library for floating point evaluation of
trig-like functions, changing back to our own code wouldn't be difficult.

Barton