diff --git a/rtl/objpas/math.pp b/rtl/objpas/math.pp index c21e51ffe2..92d95d4ed6 100644 --- a/rtl/objpas/math.pp +++ b/rtl/objpas/math.pp @@ -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; diff --git a/tests/webtbs/tw39867.pp b/tests/webtbs/tw39867.pp new file mode 100644 index 0000000000..da904a5e56 --- /dev/null +++ b/tests/webtbs/tw39867.pp @@ -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.