mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-29 14:40:25 +02:00
* fixed Math.Tanh as proposed by Paolo Valle, resolves #39867
This commit is contained in:
parent
533cd82922
commit
9e14dee1c3
@ -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
11
tests/webtbs/tw39867.pp
Normal 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.
|
Loading…
Reference in New Issue
Block a user