Karim Belabas on Fri, 09 Feb 2024 19:31:30 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: floor(tanh(91)) depends on the precision


* Ruud H.G. van Tol [2024-02-09 18:48]:
> 
> On 2024-02-09 18:25, Georgi Guninski wrote:
> > There was discussion about this on sage-devel mailing list.
> > I don't claim it is a bug, just FYI:
> > 
> > ? floor(tanh(91))
> > %1 = 1
> > ? default(realprecision,10^4)
> > ? floor(tanh(91))
> > %3 = 0
> 
> ? default(realprecision, 79)
> ? tanh(91)
> %2 = 0.999...
> 
> ? default(realprecision, 78)
> ? tanh(91) < 1
> %3 = 1
> 
> See also https://www.wolframalpha.com/input?i=tanh%2891%29
> and click on [More digits].

Not a bug, rather an intrinsic limitation: 'tanh(91)' means
"converting 91 to floating point at the current default accuracy then
return the floating point number tanh(91.0)".
.
The tanh function is computed as (t-1) / (t+1) for some huge t = exp(2*91.0);
but at low accuracy, we have t - 1.0 = t + 1.0 = t (if t is large enough),
using standard floating point computation rules.

In fact, the tanh function returns a floating point number which is exactly
equal to 1. Hence it's floor is computed correctly as 1.

The return value is actually close enough to the actual result: we do
have |tanh(91) - 1| < 10^(-78) in exact arithmetic (using mathematical
definitions, not floating point arithmetic), so PARI's result conforms
to the specification.

Cheers,

    K.B.
-- 
Pr. Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/