* fixed Math.Tanh as proposed by Paolo Valle, resolves #39867

This commit is contained in:
florian 2022-08-17 20:56:15 +02:00
parent 533cd82922
commit 9e14dee1c3
2 changed files with 21 additions and 7 deletions

View File

@ -945,15 +945,18 @@ function sinh(x : float) : float;
sinh:=copysign(0.5*(temp-1.0/temp),x);
end;
Const MaxTanh = 5678.22249441322; // Ln(MaxExtended)/2
function tanh(x : float) : float;
var Temp : float;
var
tmp:float;
begin
if x>MaxTanh then exit(1.0)
else if x<-MaxTanh then exit (-1.0);
temp:=exp(-2*x);
tanh:=(1-temp)/(1+temp)
if x < 0 then begin
tmp:=exp(2*x);
result:=(tmp-1)/(1+tmp)
end
else begin
tmp:=exp(-2*x);
result:=(1-tmp)/(1+tmp)
end;
end;
function arccosh(x : float) : float; inline;

11
tests/webtbs/tw39867.pp Normal file
View File

@ -0,0 +1,11 @@
uses
math;
begin
writeln(tanh(-354));
if tanh(-354)<>-1 then
halt(1);
writeln(tanh(-355));
if tanh(-355)<>-1 then
halt(1);
end.